Search Results

Search found 768 results on 31 pages for 'cakephp 2 1'.

Page 12/31 | < Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >

  • CakePHP's list problem

    - by jun
    Hi there. I have this table in my DB: Group - ID-Name - 1 -abc - 2 -def - 3 -ghi Pages - id-group_id-name - 1 -1 -home - 2 -1 -about us Now I wanted to make a select box that groups them by 'group' using: function add() { $this->set('pages', $this->Page->find('list', array('fields' => array('Page.id', 'Page.name', 'Page.group_id')))); } In my add.ctp: echo $form->input('group_id', array('options' => $pages)); The output: <select name="data[Page][id]" id="PageId"> <optgroup label="1"> <option value="1">Home</option> <option value="2">About Us</option> </optgroup> </select> I wanted the optgroup to display the actual group name not the group id like: <select name="data[Page][id]" id="PageId"> <optgroup label="abc"> <option value="1">Home</option> <option value="2">About Us</option> </optgroup> </select> I have tried this one: $this->Page->find('list', array('conditions' => 'Group.id = Page.id', 'fields' => array('Page.id', 'Page.name', 'Group.name'))); But 'Group.id' and 'Group.name' is unknown. Thanks!

    Read the article

  • Making one of a group of similar form fields required in CakePHP

    - by Pickledegg
    I have a bunch of name/email fields in my form like this: data[Friend][0][name] data[Friend][1][name] data[Friend][2][name] etc. and data[Friend][0][email] data[Friend][1][email] data[Friend][2][email] etc. I have a custom validation rule on each one that checks to see if the corresponding field is filled in. Ie. if data[Friend][2][name] then data[Friend][2][email] MUST be filled in. FYI, heres what one of the two rules look like: My form validation rule: ( I have an email validation too but that's irrelevant here) 'name' => array( 'checkEmail' => array( 'rule' => 'hasEmail', 'message' => 'You must fill in the name field', 'last' => true ) ) My custom rule code: function hasEmail($data){ $name = array_values($data); $name = $name[0]; if(strlen($name) == 0){ return empty($this->data['Friend']['email']); } return true; } I need to make it so that one of the pairs should be filled in as a minimum. It can be any as long as the indexes correspond. I can't figure a way, as if I set the form rule to be required or allowEmpty false, it fails on ALL empty fields. How can I check for the existence of 1 pair and if present, carry on? Also, I need to strip out all of the remaining empty [Friend] fields, so my saveAll() doesn't save a load of empty rows, but I think I can handle that part using extract in my controller. The main problem is this validation. Thanks.

    Read the article

  • Cakephp Insert Ignore Feature?

    - by SeanDowney
    Is there a way to do an "insert ignore" in cake without using a model-query function? $this->Model->save(array( 'id' => NULL, 'guid' => $guid, 'name' => $name, )); Generates error: Warning (512): SQL Error: 1062: Duplicate entry 'GUID.....' for key 'unique_guid' [CORE/cake/libs/model/datasources/dbo_source.php, line 524] It would be great to be able to set some flag or option that says "don't care"

    Read the article

  • Zend Framework or CakePHP?

    - by gorzan
    My group is going to attempt to build a new CMS from scratch, designed to serve the needs of our organization. It should be noted that none of us have any formal programming education, but we've picked up this and that from developing different websites, among others the one our community uses now. We've decided to program the new CMS in PHP, with total MVC seperation. Not wanting to re-invent all the little cogs and wheels needed for such a potentially large project as this, we've been looking into using a PHP framework, and some googling and blog-surfing landed us in a discussion: Zend vs Cake? Anyone have any useful input here? Also, any other tips for embarking on this project would be appreciated. (Except for suggestions for existing CMSes, we know they're out there.) EDIT: It seems I was a bit unclear. None of us are NEW to PHP - in fact, we all have fairly extensive experience from previous projects, including the current solution our community's website runs on which we built ourselves. The decision to not use an existing CMS is a very informed one, so although I appreciate all the good suggestions we really are going to do this ourselves. So. Zend vs Cake?

    Read the article

  • Unable to save to wincache from cakePHP shell

    - by Phillaf
    I'm trying to retrieve the weather from wunderground.com through their API, and store it in wincache. For testing purposes I made this function in the News model: public function updateWeather(){ $results = file_get_contents('http://api.wunderground.com/api/**api_key**/conditions/q/CA/Montreal.json'); $results = json_decode($results); return Cache::write('weather', $results); } It works fine when I call this from the controller. However, I can't figure why that same function doesn't work when called from the console. I made this shell in order to eventually add this to windows task scheduler. class WeatherShell extends AppShell { public $uses = array('News'); public function main() { $this->News->updateWeather(); } } When running this, I see that $results is correctly populated. I get 'true' from Cache::write(), however, I get 'false' when trying to read. What subtlety am I missing?

    Read the article

  • Cakephp: Correct way to resolve hasMany - hasMany relation

    - by Chris
    I have three models: Company, Car, Passenger Company hasMany Cars Car hasMany Passenger These relations seem to work independetly: Car shows all Passengers and Company shows all Cars. But I cannot resolve the Company - Passenger (Show all Passengers of a Company). My controller for Company: function index(){ //grab all companies and pass it to the view: $companies = $this->Company->find('all'); $this->set('companies', $companies); } This displays all companies with all their respective cars. However the array does not contain an entry for passenger. What do I have to do to completely resovle the Company - Car - Passenger relation?

    Read the article

  • Cakephp - Banner Problem

    - by Joe Elliott
    Hi guys I have a banner rotator on my main page and it was working but it has stopped. All I have done before it stopped was modified some of the db fields. I added to fields position and company and deleted the field 'description.' It was a friend of a friend that made this part of the site for me while i was on holiday so i dont know which files i should show you cos dont know exactly what hes done but im guessing the following ones are the ones you need. banner_view <div id="banner"> <?php if(!empty($banners) && ($banners['Banner']['position']=='Top')){ foreach($banners as $banner){ ?> <a href="<?php echo $banner['Banner']['url']; ?>"><img src="<?php echo $banner['Banner']['path']; ?>" alt="<?php echo $banner['Banner']['company']; ?>" /></a> <?php } } ?> </div> banner_controller <?php class BannersController extends AppController { var $name = 'Banners'; var $helpers = array('Html', 'Form', 'Ajax','Javascript'); var $layout = 'ajax'; var $components = array('Session', 'Cookie'); function beforeFilter() { parent::beforeFilter(); $this->Auth->allow('index','featrot'); if(strpos($this->here, 'admin')) { $this->layout = 'admin'; } } function index() { Configure::write('debug',0); $this->Banner->recursive = 0; $this->paginate['Banner']; $banners = $this->paginate(); if($banners) { $this->set('banners', $banners); } } function featrot() { Configure::write('debug',0); $this->Banner->recursive = 0; $this->paginate['Banner']; $banners = $this->paginate(); if($banners) { $this->set('banners', $banners); } } function admin_edit(){ $this->pageTitle='Admin section - .: Banners Edit:.'; $banners = $this->Banner->find('first'); $id = $banners['Banner']['id']; if (!empty($this->data)) { $this->Banner->id = $id; if ($this->Banner->save($this->data)) { $this->Session->setFlash(__('The Banner has been updated', true)); } else { $this->Session->setFlash(__('The Banner could not update. Please, try again.', true)); } } if (empty($this->data)) { $this->data = $this->Banner->read(null, $id); } } function admin_display_banners($id=null){ $this->pageTitle='Admin section - .: Banners Setting :.'; if (!empty($this->data)) { $this->Banner->id = $id; if ($this->Banner->save($this->data)) { $this->Session->setFlash(__("Banner#$id has been updated", true)); $this->Banner->id = null; } else { $this->Session->setFlash(__("Banner#$id could not update. Please, try again.", true)); } } $this->data = null; $this->Banner->recursive = -1; $this->paginate['Banner']; $banners = $this->paginate('Banner'); $this->set('banners', $banners); } } ?> banner_model <?php class Banner extends AppModel { var $name = 'Banner'; } ?> Hope this is all the details you need. Thanks in advance folks :) Joe :)

    Read the article

  • cakephp - try/catch an Action

    - by joshs
    I would like to somehow apply a try catch statement to all Actions as a backstop for any uncaught exceptions. I think this would be particularly helpful for Ajax Actions, because the catch statement could send back a default 4xx status code. Prototype's onFailure() function could then do the client-side error handling. How can I do this without wrapping the Action call with a try/catch in the cake dispatcher like this: try { output = $controller->dispatchMethod($params['action'], $params['pass']); } catch {...} Does anybody have a suggestion or another workable strategy for gaining this functionality without touching the dispatcher? How do people feel about putting exception handling in the Displatcher? I imagine when cake drops php 4 support, there will be a built-in mechanism for this.

    Read the article

  • cakephp paginate multiple habtm

    - by izmanromli
    hi guys, i have multiple habtm like these : // User model var $hasMany = array('Post'); // Post model var $hasAndBelongsToMany = array('Category', 'Tag'); // Category model var $hasAndBelongsToMany = array('Post'); // Tag model var $hasAndBelongsToMany = array('Post'); I tried to fetch all post along with its user and tags (within a certain category), somehow if i fetch tags, the result was wrong. $this->paginate = array ( 'Post' => array ( 'limit' => 2, 'fields' => array( 'Post.title', 'Post.content', 'Post.slug', 'Post.created', 'Tag.name', 'User.username', 'User.created', 'User.post_count', 'User.avatar_file_name'), 'joins' => array ( array( 'table' => 'categories_posts', 'alias' => 'CategoriesPost', 'type' => 'inner', 'conditions'=> array('CategoriesPost.post_id = Post.id') ), // FETCH USER array( 'table' => 'users', 'alias' => 'User', 'type' => 'inner', 'conditions'=> array('Post.user_id = User.id') ), // FETCH TAGS array( 'table' => 'posts_tags', 'alias' => 'PostsTag', 'type' => 'inner', 'conditions'=> array('PostsTag.post_id = Post.id') ), array( 'table' => 'tags', 'alias' => 'Tag', 'type' => 'inner', 'conditions'=> array('Tag.id = PostsTag.tag_id') ), array( 'table' => 'categories', 'alias' => 'Category', 'type' => 'inner', 'conditions'=> array('Category.id = CategoriesPost.category_id', 'Category.slug' => $slug) ) ) ) ); $posts = $this->paginate(); could anyone gimme a solution since i'm a newbie? many thanks...

    Read the article

  • CakePHP Bake association problem

    - by Apu
    I have only two tables in my database with a one-to-many relationship between them (user hasMany messages) and am trying to get basic CRUD functionality going. Bake detects the associations correctly and specifies them correctly inside the model classes, but in controllers and views it looks like Cake doesn't know anything about those associations -- I don't even get a select tag for user_id when I go add a new message. Has anyone come across this problem before? What can I be doing wrong? Table structure appears to be fine: CREATE TABLE users ( id int(11) NOT NULL AUTO_INCREMENT, username varchar(255) NOT NULL, `password` varchar(255) NOT NULL, email varchar(255) NOT NULL, created datetime NOT NULL, modified datetime NOT NULL, PRIMARY KEY (id) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `messages` ( `id` int(11) NOT NULL AUTO_INCREMENT, `user_id` int(11) NOT NULL, `content` varchar(255) NOT NULL, `created` datetime NOT NULL, `modified` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=1 ;

    Read the article

  • Load a controller into an other controller in cakephp

    - by john
    im developing a web application, using multiple pages, each with their own controller. The problem now is that there are some variables in a controller, created for one page, that are required for an other page ( with a different controller). Therefor i need to load one controller into the other one. I did this by adding App::import('Controller', 'sections'); $sections= new sectionsController; $sections-constructClasses(); to the controller, but this doens't seem to work.. Maybe u guys have some ideas? Thnx in advance!

    Read the article

  • CakePHP: Action runs twice, for no good reason.

    - by tehstu
    Greetings everyone! I have a strange problem with my cake (cake_1.2.0.7296-rc2). My start()-action runs twice, under certain circumstances, even though only one request is made. The triggers seem to be : - loading an object like: $this-Questionnaire-read(null, $questionnaire_id); - accessing $this-data If I disable the call to loadAvertisement() from the start()-action, this does not happen. If I disable the two calls inside loadAdvertisement(): $questionnaire = $this-Questionnaire-read(null, $questionnaire_id); $question = $this-Questionnaire-Question-read(null, $question_id); ... then it doesn't happen either. Why? See my code below, the Controller is "questionnaires_controller". function checkValidQuestionnaire($id) { $this->layout = 'questionnaire_frontend_layout'; if (!$id) { $id = $this->Session->read('Questionnaire.id'); } if ($id) { $this->data = $this->Questionnaire->read(null, $id); //echo "from ".$questionnaire['Questionnaire']['validFrom']." ".date("y.m.d"); //echo " - to ".$questionnaire['Questionnaire']['validTo']." ".date("y.m.d"); if ($this->data['Questionnaire']['isPublished'] != 1 //|| $this->data['Questionnaire']['validTo'] < date("y.m.d") //|| $this->data['Questionnaire']['validTo'] < date("y.m.d") ) { $id = 0; $this->flash(__('Ungültiges Quiz. Weiter zum Archiv...', true), array('action'=>'archive')); } } else { $this->flash(__('Invalid Questionnaire', true), array('action'=>'intro')); } return $id; } function start($id = null) { $this->log("start"); $id = $this->checkValidQuestionnaire($id); //$questionnaire = $this->Questionnaire->read(null, $id); $this->set('questionnaire', $this->data); // reset flow-controlling session vars $this->Session->write('Questionnaire',array('id' => $id)); $this->Session->write('Questionnaire'.$id.'currQuestion', null); $this->Session->write('Questionnaire'.$id.'lastAnsweredQuestion', null); $this->Session->write('Questionnaire'.$id.'correctAnswersNum', null); $this->loadAdvertisement($id, 0); $this->Session->write('Questionnaire'.$id.'previewMode', $this->params['named']['preview_mode']); if (!$this->Session->read('Questionnaire'.$id.'previewMode')) { $questionnaire['Questionnaire']['participiantStartCount']++; $this->Questionnaire->save($questionnaire); } } function loadAdvertisement($questionnaire_id, $question_id) { //$questionnaire = array(); $questionnaire = $this->Questionnaire->read(null, $questionnaire_id); //$question = array(); $question = $this->Questionnaire->Question->read(null, $question_id); if (isset($question['Question']['advertisement_id']) && $question['Question']['advertisement_id'] > 0) { $this->set('advertisement', $this->Questionnaire->Question->Advertisement->read(null, $question['Question']['advertisement_id'])); } else if (isset($questionnaire['Questionnaire']['advertisement_id']) && $questionnaire['Questionnaire']['advertisement_id'] > 0) { $this->set('advertisement', $this->Questionnaire->Question->Advertisement->read(null, $questionnaire['Questionnaire']['advertisement_id'])); } } I really don't understand this... it don't think it's meant to be this way. Any help would be greatly appreciated! :) Regards, Stu

    Read the article

  • CakePHP: Custom Function in bootstrap that uses $ajax->link not working

    - by nekko
    Hello I have two questions: (1) Is it best practice to create global custom functions in the bootstrap file? Is there a better place to store them? (2) I am unable use the following line of code in my custom function located in my bootstrap.php file: $url = $ajax->link ( 'Delete', array ('controller' => 'events', 'action' => 'delete', 22 ), array ('update' => 'event' ), 'Do you want to delete this event?' ); echo $url; I receive the following error: Notice (8): Undefined variable: ajax [APP\config\bootstrap.php, line 271] Code } function testAjax () { $url = $ajax->link ( 'Delete', array ('controller' => 'events', 'action' => 'delete', 22 ), array ('update' => 'event' ), 'Do you want to delete this event?' ); testAjax - APP\config\bootstrap.php, line 271 include - APP\views\event\queue.ctp, line 19 View::_render() - CORE\cake\libs\view\view.php, line 649 View::render() - CORE\cake\libs\view\view.php, line 372 Controller::render() - CORE\cake\libs\controller\controller.php, line 766 Dispatcher::_invoke() - CORE\cake\dispatcher.php, line 211 Dispatcher::dispatch() - CORE\cake\dispatcher.php, line 181 [main] - APP\webroot\index.php, line 91 However it works as intended if I place that same code in my view: <a onclick=" event.returnValue = false; return false;" id="link1656170149" href="/shout/events/delete/22">Delete</a> Please help :) Thanks in advance!!

    Read the article

  • Cakephp 1.3, router and authentication problem

    - by Zhlobopotam
    Trying to implements simple privileges for admin user. Don't need huge acl rules and groups system. There are admin users, overs - just registered users. They can't access actions with admin prefix. So It was implemented in cakephp1.2 version with following code in app_controller: function isAuthorized() { if (isset($this->params[Configure::read('Routing.admin')])) { if ($this->Auth->user('admin') != 1) { return false; } } return true; } But in 1.3 Routing.admin had been deprecated. How to rewrite it for use with 1.3 framework? Need some help.

    Read the article

  • CakePHP - Just Layout?

    - by Kieran
    I want to set $this->layout to json in the controller action. In the json layout, there will be a line saying $this->Javascript>object(); which will parse through the data given to it by the controller, and output the jSON. However, creating a new view file for each jSON request, eg. recipe_view, ingredient_view isn't necessary, I just need a layout. Is there a way to bypass the view file altogether and have just the layout, without the notorious Missing View! error? Many Thanks Kieran

    Read the article

  • How to debug when CakePHP Model::save() doesn't attempt an INSERT

    - by RyOnLife
    I am having a bear of a time saving the simplest record from a model called ItemView: if($this->save($this->data)) { echo 'worked'; } else { echo 'failed'; } Where $this-data is: Array ( [ItemView] => Array ( [list_id] => 1 [user_id] => 1 ) ) And my table is: CREATE TABLE IF NOT EXISTS `item_views` ( `id` int(11) NOT NULL auto_increment, `list_id` int(11) NOT NULL, `user_id` int(11) default NULL, `user_ip` int(10) unsigned default NULL, `created` datetime NOT NULL, PRIMARY KEY (`id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 ROW_FORMAT=FIXED AUTO_INCREMENT=1 ; Looking at the query dump in debug mode, Cake isn't even attempting an INSERT, so I have no idea how to debug. Any help would be appreciated.

    Read the article

  • Cakephp change model's title without rename model/dbtable

    - by Vincent
    I have a table that store all information about class, but because Class is reserved for class name I had to rename the table from classes to types. But in the view section I need it to be displayed as "Class", including the Paginator links. Anyway to achieve this by adding something in the Type model, without completely customize Paginator and and all view compoenents?

    Read the article

  • Customize the datetime format in Cakephp

    - by SpawnCxy
    When I use the form helper to make a time input,usaually I write code as follows <?php $options = array( 'label' => '', 'type' => 'datetime', 'timeFormat'=>'24', 'separator'=>'-' ); echo $form->input('Service.endtime',$options); ?> But now I get a problem that I want to make a time input style such as month-day-hour Then how can do this with setting some parameters in the helper?Suggestions would be appreciated.

    Read the article

  • Country/State Dropdown in CakePHP

    - by raheelonline
    How do i deal with dependent combo boxes in the views with the form helper. For example: Country Select Box (Choosing a country shall filter out the states of the selected country) States Select Box This should happen with the help of Javascript / Jquery etc. I came across an example for the same with Cake's core AJAX helper but it would be very nice if someone can help with a Javascript example. Thanks

    Read the article

  • Adding multiple parameters to a Resources::url() request in CakePHP

    - by skerit
    For the Javascript helper I need to create my links like this: Resources::url('Product::addToOrder', $id) But how do I add multiple parameters? I tried to do it in an array, but that did not work. Here's the js event: $this->Js->event( 'click', $this->Js->request(Resources::url('Product::addToOrder', $id), array('async' => true, 'update' => '#order') ) );

    Read the article

  • Internet Explorer randomly drops sessions between pages in cakePHP

    - by Emerson Taymor
    Hello everyone, I've come across an extremely unusual bug that my team has literally no idea how to solve. Doing some research, I found some similar solutions that I thought would work, but alas did not. Here is my situation, let me know if I can provide additional insight to help solve the problem. The first step is that someone chooses a country via a flash map. Flash passes this region name (as well as a date) through the URL, which we then convert to a session. The next page contains no Flash and doesn't display the selected region, but it does hold on to it for further down the process. Everything works perfectly in Safari and Firefox; however, in IE sometimes unexpected results occur. Frequently (but not always), the session is dropped completely and no sessions are stored between the first and 2nd pages. Here are the steps that I have taken thus far, unsuccessfully: 1. Changed Security from Medium - Low 2. Changed CheckUserAgent from True - False 3. Changed storing of sessions from PHP - Database Some additional information that may be useful: I have tried printing out the session data in Debug (debug($_SESSION) on my view file and debug set to 2 in config). In Internet Explorer everything prints out as expected EXCEPT when the region and date don't get set. For example: If the region and date don't get set NOTHING is printed out for debug. I don't get the session details at the top, and I don't get the normal dump of calls at the bottom of the page either. I am not using redirection on these pages. Please let me know if you have ANY idea of what is causing this or any solutions. I am beyond frustrated and have tried as much as I can to solve this. Thanks!

    Read the article

  • [CakePHP] htmlspecialchars

    - by user198003
    hi all, if i submit data like my string using form on insert/edit view, on a list view i'll get my string as italic (like here). how can i avoid that, and to have my string (with visible all html tags) on all forms? tnx in adv!

    Read the article

< Previous Page | 8 9 10 11 12 13 14 15 16 17 18 19  | Next Page >