Custon Query In View?
Hello. The code below is in my index View. I use it to place into a table all the articles (from all sections) of my database. How can i alter it to show only articles from a specific section (e.g. section_id=1)? $i = 0; foreach ($articles as $article): $class = null; if ($i++ % 2 == 0) { $class = ' class="altrow"'; } echo $html->link($article['Article']['title'], array('controller'=> 'articles', 'action'=>'view', $article['Article']['id'])); endforeach; Thanks in advance! --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Re: Model Assosiations
Because my real question (before starting coding) isn't clear in the above message, here it is: I just want to have a model to publish the articles (which are written in admin model and have an association with the section model) to the frontpage so visitors can view them there. I'm trying to do this with the code above. Is it the right approach or i need to think something else? --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Model Association
Hello, i have a question: i have a model named "admin" where the admins of the site can write an article, edit it, delete it etc. It's assosiated with model "section" so every article must belong to a section. How can i make a model "articles" that doesn't have a database connected to it but it can just use the fields from the other model to show them to the visitor of the site? Let's say it will be the frond- end of the site. When sb is going to the site i want it to go to / articles/ (i know how to change it from routes.php) and show to the user the all the published articles, e.g. sorted by their section. I'm giving this example so i can help you understand what i want to do. The reason that i don't want to use the admin model to view to visitors the articles is that i don't want them to have any access to the admin model (it will be password protected), for security reasons. I just want to have a model to publish the articles (which were written in admin model) to the frontpage so visitors can view them there. I'm trying to do this with the code below. Is it the right approach or i need to think something else? The Admin model: class Admin extends AppModel { var $name = 'Admin'; var $belongsTo = array ('Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); var $hasMany = array ('Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } The Section model: class Section extends AppModel { var $name = 'Section'; var $hasMany = array ( 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); } The articles model: class Article extends AppModel { var $name = 'Article'; var $useTable = false; var $belongsTo = array ( 'Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } I did the above but i don't think it's the right thing to do.. Thank you for your time --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Model Assosiations
Hello, i have a question: i have a model named "admin" where the admins of the site can write an article, edit it, delete it etc. It's assosiated with model "section" so every article must belong to a section. How can i make a model "articles" that doesn't have a database connected to it but it can just use the fields from the other model to show them to the visitor of the site? Let's say it will be the frond- end of the site. When sb is going to the site i want it to go to / articles/ (i know how to change it from routes.php) and show to the user the all the published articles, e.g. sorted by their section. I'm giving this example so i can help you understand what i want to do. The reason that i don't want to use the admin model to view to visitors the articles is that i don't want them to have any access to the admin model (it will be password protected), for security reasons. My approach is right? The Admin model: class Admin extends AppModel { var $name = 'Admin'; var $belongsTo = array ('Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); var $hasMany = array ('Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } The Section model: class Section extends AppModel { var $name = 'Section'; var $hasMany = array ( 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); } The articles model: class Article extends AppModel { var $name = 'Article'; var $useTable = false; var $belongsTo = array ( 'Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } I did the above but i don't think it's the right thing to do.. Thank you for your time --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---
Front-end model
Hello, i have a question: i have a model named "admin" where the admins of the site can write an article, edit it, delete it etc. It's assosiated with model "section" so every article must belong to a section. How can i make a model "articles" that doesn't have a database connected to it but it can just use the fields from the other model to show them to the visitor of the site? Let's say it will be the frond- end of the site. When sb is going to the site i want it to go to / articles/ (i know how to change it from routes.php) and show to the user the all the published articles, e.g. sorted by their section. I'm giving this example so i can help you understand what i want to do. The reason that i don't want to use the admin model to view to visitors the articles is that i don't want them to have any access to the admin model (it will be password protected), for security reasons. My approach is right? The Admin model: class Admin extends AppModel { var $name = 'Admin'; var $belongsTo = array ('Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); var $hasMany = array ('Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } The Section model: class Section extends AppModel { var $name = 'Section'; var $hasMany = array ( 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Article' => array( 'className' => 'Article', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id') ); } The articles model: class Article extends AppModel { var $name = 'Article'; var $useTable = false; var $belongsTo = array ( 'Section' => array( 'className' => 'Section', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'section_id'), 'Admin' => array( 'className' => 'Admin', 'conditions'=> null, 'order'=> null, 'foreignKey'=>'admin_id') ); } I did the above but i don't think it's the right thing to do.. Thank you for your time --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Cake PHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/cake-php?hl=en -~--~~~~--~~--~--~---