• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sharing data between view partials

#12
[eluser]John_Betong[/eluser]
[quote author="xwero" date="1224168440"]What is too complex to understand in the second example?[/quote]
 
The reason it is too difficult is there are too many variables on the one line.
 
To achieve the same result I would add an extra line and make the code (for me) easier to read at a glance.
Code:
//==========================================================================  
  function _myView($msg=array('one', 'two', 'three'), $msg_name='$msg_name not passed') {
    $style = 'text-align:left; font-size:1.0em; background:#ccc none; color:#00f;
              width:42%; margin:1em auto; border:dotted; font-weight:bold';
              
    echo "<pre style='$style'>";
      echo "Function: <b>" .__FUNCTION__ .' : ' .__FILE__ .' line(' .__LINE__ .')</b>' .BR;
      echo '<br />';
      echo '<b>' .$msg_name .'</b><br />';
      print_r($msg);
      echo '<br />';
    echo "</pre>";
  }
  
  //==================================================
    function index($start_page=5) {
    $glob_partials['title'] = 'My Great Title';

    $content_Xwero          = array_merge($glob_partials, array('body'=>'long text'));
    
    $content_John           = $glob_partials;
    $content_John['body']   = 'long text';
  
    // display the results  
    $this->_myView($glob_partials, '$glob_partials');
    $this->_myView($content_Xwero, '$content_Xwero');
    $this->_myView($content_John, '$content_John');
    die;
  }//end test

&nbsp;
&nbsp;
Here are the results
Code:
Function: _myView : C:\awww\ci_jokes\controllers\joke.php line(35)

$glob_partials
Array
(
    [title] => My Great Title
)

Function: _myView : C:\awww\ci_jokes\controllers\joke.php line(35)

$content_Xwero
Array
(
    [title] => My Great Title
    [body] => long text
)

Function: _myView : C:\awww\ci_jokes\controllers\joke.php line(35)

$content_John
Array
(
    [title] => My Great Title
    [body] => long text
)
&nbsp;
&nbsp;
&nbsp;


Messages In This Thread
Sharing data between view partials - by El Forum - 10-15-2008, 09:53 AM
Sharing data between view partials - by El Forum - 10-15-2008, 10:31 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:05 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:11 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:19 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:23 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:33 AM
Sharing data between view partials - by El Forum - 10-16-2008, 02:54 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:12 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:43 AM
Sharing data between view partials - by El Forum - 10-16-2008, 03:47 AM
Sharing data between view partials - by El Forum - 10-16-2008, 04:27 AM

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.