Re: redirect not working

2014-05-30 Thread Andrew Barry
Although  the above fixed it , the issue remains the below code didnt work 
as expected, in fact it doesnt work. why?

class AppController extends Controller {

 public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'posts', 'action' => 
'index'),
'logoutRedirect' => array(
'controller' => 'users',
'action' => 'login'

),
'authorize' => array('Controller') // Added this line
)
);

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: redirect not working

2014-05-30 Thread Andrew Barry
This solved the problem as I need to specify the redirect in the login
I also tried in the beforefilter without success

public function login() {
if ($this->request->is('post')) {
if ($this->Auth->login()) {
   return $this->redirect(array('controller' => 'posts','action' => 
'index')); 
//return $this->redirect($this->Auth->redirect());
}
$this->Session->setFlash(__('Invalid username or password, try 
again'));
}
}

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: form data

2014-05-24 Thread Andrew Barry
what happens is that the form in  myform2 displays but the id fields are 
blank dropdown.
These fields are not autoincrement.
I submit and I can get the subject field displayed in myform3 but not id or 
date fields.




controller
public  function myform3()
{
   
   if($this->request->is('post')) {
$this->set('tutorInput', $this->request->data);
}
}



myform2 view
   echo $this->Form->create(array('action' => 'myform3'));
echo $this->Form->input('teacher_id');   //text
echo $this->Form->input('student_id');   //text
 echo $this->Form->input('subject');   //text
echo $this->Form->input('sessiondate', 
   array('label' => 'Session'));  
echo $this->Form->input('sessiontime', 
   array('label' => 'time'));  
 echo $this->Form->input('available');  
  echo $this->Form->end('submit'); 
 
myform3 view

  echo ''. $tutorInput['Tutorsession']['subject'].'';
   echo ''. $tutorInput['Tutorsession']['sessiondate'].'';
 echo ''. $tutorInput['Tutorsession']['student_id'].'';
   echo ''. $tutorInput['Tutorsession']['sessiontime'].'';
 echo '';
   

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: form data

2014-05-24 Thread Andrew Barry
Ok I was hoping I wouldnt get such a response.

I have been looking at this book and you have to admit , it just isnt 
always going to help you do a complete example.

data goes back to the controller in a 

$this->request->data['MyModel']['title']; and this means I can do what and 
where ? is there an example anywhere?


http://book.cakephp.org/2.0/en/controllers/request-response.html  //this 
doesnt help

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


form data

2014-05-24 Thread Andrew Barry
Hi,

I created a form and a submit button.
After that I want to 
1) display certain fields back to another view  and that means the posted 
data is handled by the controller?
I am really finding this hard to get a complete example on this and cakephp 
book isnt helping as yet.

echo $this->Form->create();

echo $this->Form->input('username');   //text
echo $this->Form->input('password');   //password
echo $this->Form->input('birth_dt', 
   array('label' => 'Date of birth',
  'dateFormat' => 'DMY',
  'minYear' => date('Y') - 70,
  'maxYear' => date('Y') - 
18));   
 echo $this->Form->checkbox('done');
echo $this->Form->input('field', array(
'options' => array(1, 2, 3, 4, 5),
'empty' => '(choose one)'));
echo $this->Form->end('submit');

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: load 2 models in controller

2014-05-24 Thread Andrew Barry
I dont think it should be this complicated.
You are just loading a model in a controller and i see many examples of ths 
but i cant get it to work.

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: filter data with controller or model?

2014-05-23 Thread Andrew Barry
I tell a lie, I had a plural model name so I fixed this and it works

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: filter data with controller or model?

2014-05-23 Thread Andrew Barry
Hi,

Didnt work sorry and I dont know how to fix this. You have to be careful 
with the single quotes placed here because they copy across. 

*Error: * SQLSTATE[42S22]: Column not found: 1054 Unknown column 
'Tutorsessions.teacher_id' in 'where 
clause'??  This col exists so I 
dont know what to do !


In my model I have this

public function findstuff($teacherId = null) {
if (!$teacherId) {
return array(); }

 return $this->find('all',
array('conditions' => array('Tutorsessions.teacher_id' => 
$teacherId)));
}

I my controller I have

public  function home2()
{
   
$teacherId=1;
$this->set('tutor',$this->Tutorsession->findstuff($teacherId));
}


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


Re: load 2 models in controller

2014-05-23 Thread Andrew Barry
I need to know how this is done . ( My example was just that).
I just want to load another tables data in on the same view as another 
table data (just assume the data is not related).


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


load 2 models in controller

2014-05-23 Thread Andrew Barry
Hi,

In my view I want to display data from 2 tables (maybe not related).
I read i do the following to load 2 model in a controller and simply access 
the other model in the view.

I get an error in the view file so this method of loading 2 models in a 
contrller doesnt work?

Undefined index: Teacher



class TutorsessionsController extends AppController
{

//do I need to add anything here like public $uses?

public  function index()
{
   $this->set('tutor',$this->Tutorsession->find('all')); 
 
   
   $this->loadModel('Teacher');
$this->set('teacher', $this->Teacher->find('all'));
}

in View

.
  foreach ($teacher as $item): 
echo ''. $item['Teacher']['id']. '';

-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


filter data with controller or model?

2014-05-23 Thread Andrew Barry
In cakephp what is the method to filter data on a database request.
Do I filter the data from a model or a controller?

Say if I have a table with 1000's of rows and I only want to select rows on 
a condition , like a where clause on sql.

The user enters in a certain fields to select rows from a table.

I then pass this variable to the controller and the controller filters this 
data or is the model supposed to filter the rows selected?

I didnt quite see this clearly from the cakephp docs.
I am not sure if a model or controller is the best way to go about it.

a controller would do ///
 public function view($id = null) {
  $post = $this->Post->findById($id);


$this->set('post', $post);
}

a model would do something like the below where you set the condition and this 
seems a really messy way to go about things.

class Recipe extends AppModel {
public $hasAndBelongsToMany = array(
'Ingredient' =>
array(
'className' => 'Ingredient',
'joinTable' => 'ingredients_recipes',
'foreignKey' => 'recipe_id',
'associationForeignKey' => 'ingredient_id',
'unique' => true,
'conditions' => '',
'fields' => '',
'order' => '',
'limit' => '',
'offset' => '',
'finderQuery' => '',
'with' => ''
)
);
}


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.


displaying 2 tables

2014-05-20 Thread Andrew Barry
Hi,
I have just started cakephp and got working an example.

if you look at a hello world example from cakephp then I have these files.
I have a table name called users and looking at the blog tutorial that name 
users should refer to a database name .

q1)My example works but what is correct? Is the name 'users' a table or 
databasename?

q2)How do I refer to 2 database tables in the 1 view as do I need another 
model and controller for every database table I access?

http://book.cakephp.org/2.0/en/tutorials-and-examples/blog/part-two.html







http://127.0.0.1/cakephp/users/*/
echo "Hello World";
?>


-- 
Like Us on FaceBook https://www.facebook.com/CakePHP
Find us on Twitter http://twitter.com/CakePHP

--- 
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to cake-php+unsubscr...@googlegroups.com.
To post to this group, send email to cake-php@googlegroups.com.
Visit this group at http://groups.google.com/group/cake-php.
For more options, visit https://groups.google.com/d/optout.