On Tue, Jan 25, 2011 at 5:21 AM, andy_the ultimate baker <[email protected]> wrote: > hi, > i m on one script where i want to store data of one variable in to the > file by creating in in script itself. > i have collected data as fallows in $stateJs variable. > > <?php > class CitiesController extends AppController{ > var $name = 'Cities'; > var $helper = array('html' ,'form'); > var $uses = array('City', 'State'); > > function admin_select(){ > $states = $this->State->find('all', array('order' => > array('State.created DESC'))); > // print_r($states);exit; > $stateJs =""; > foreach($states as $state){ > $stateJs .= 'var'." > ".$state['State']['title']."".'_list'."".'='; > $stateJs .= "<SELECT NAME='drpcity' id='drpcity' > class='dropdown1_adpro_businesstype' > onchange='enable_othercity(this.value);' > style='width: > 170'><OPTION VALUE='sel'>--------- Select a City ---------</OPTION>"; > $cities = $this->City->find('all', > array('conditions'=>array('state_code'=>$state['State'] > ['state_code']))); > //print_r($cities);exit; > foreach($cities as $city){ > $stateJs .="<option value= ".$city['City']['id'].">"; > $stateJs .= $city['City']['title']; > $stateJs .= "</option>"; > } > } > > $stateJs .= "</select>\n"; > echo $stateJs; > } > } > > ?> > > now i want to store $stateJs variable data by creating a file in > script.
You really shouldn't be including the mark-up in the controller. That's the view's job. Fetch the City records in the controller and pass them to the view to create your select tag. Why do you want to save this in a file? Is this for an AJAX request? Better to create an element and cache that. -- Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions. To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/cake-php
