<?php $slug = uri_segment(2); if ($slug) { $article = fuel_model('articles', array('find' => 'one', 'where' => array('slug' => $slug))); if (empty($article)) { redirect_404(); } } else { $tags = fuel_model('tags'); } if (!empty($article)) { ?> <h1><?php echo fuel_edit($article); echo $article->title; ?> </h1> <div class="author"><?php echo $article->author->name; ?> </div> <img src="<?php echo $article->image_path; ?> " alt="<?php echo $article->title_entities; ?> " class="img_right" /> <article><?php
// otherwise we search by find one if (empty($item_where)) { $item_where = array($key_field => $param); } $item = fuel_model($model, array('find' => 'one', 'where' => $item_where)); } // if no item is found, then do a redirect or 404 if no redirect exists if (empty($item)) { redirect_404(); } } else { // if no uri segment, then we do a query on the model to get a list of data if (empty($list_where)) { $list_where = array(); } $data = fuel_model($model, array('find' => 'all', 'where' => $list_where)); } ?> <?php if (!empty($item)) { ?> <?php echo fuel_block(array('view' => $item_block, 'data' => $item)); ?> <?php } else { ?>
/** * Allows you to load a view and pass data to it * * @access public * @param mixed * @return string */ function fuel_block($params) { $CI =& get_instance(); $CI->load->library('parser'); $valid = array( 'view' => '', 'view_string' => FALSE, 'model' => '', 'find' => 'all', 'select' => NULL, 'where' => '', 'order' => '', 'limit' => NULL, 'offset' => 0, 'return_method' => 'auto', 'assoc_key' => '', 'data' => array(), 'editable' => TRUE, 'parse' => 'auto', 'vars' => array(), 'cache' => FALSE, ); // for convenience if (!is_array($params)) { $new_params = array(); if (strpos($params, '=') === FALSE) { $new_params['view'] = $params; } else { $CI->load->helper('array'); $new_params = parse_string_to_array($params); } $params = $new_params; } $p = array(); foreach($valid as $param => $default) { $p[$param] = (isset($params[$param])) ? $params[$param] : $default; } // pull from cache if cache is TRUE and it exists if ($p['cache'] === TRUE) { $CI->load->library('cache'); $cache_group = $CI->config->item('page_cache_group', 'fuel'); $cache_id = (!empty($p['view_string'])) ? $p['view_string'] : $p['view']; $cache_id = md5($cache_id); $cache = $CI->cache->get($cache_id, $cache_group); if (!empty($cache)) { return $cache; } } // load the model and data $vars = (array) $p['vars']; if (!empty($p['model'])) { $data = fuel_model($p['model'], $p); $module_info = $CI->fuel_modules->info($p['model']); if (!empty($module_info)) { $var_name = $CI->$module_info['model_name']->short_name(TRUE, FALSE); $vars[$var_name] = $data; } } else { $vars['data'] = $p['data']; } $output = ''; // load proper view to parse. If a view is given then we first look up the name in the DB $view = ''; if (!empty($p['view_string'])) { $view = $p['view_string']; } else if (!empty($p['view'])) { $view_file = APPPATH.'views/_blocks/'.$p['view'].EXT; if ($CI->config->item('fuel_mode', 'fuel') != 'views') { $CI->load->module_model(FUEL_FOLDER, 'blocks_model'); // find the block in FUEL db $block = $CI->blocks_model->find_one_by_name($p['view']); if (isset($block->id)) { if (strtolower($p['parse']) == 'auto') { $p['parse'] = TRUE; } $view = $block->view; if ($p['editable'] === TRUE) { $view = fuel_edit($block->id, 'Edit Block: '.$block->name, 'blocks').$view; } } else if (file_exists(APPPATH.'views/_blocks/'.$p['view'].EXT)) { // pass in reference to global CI object $vars['CI'] =& get_instance(); // pass along these since we know them... perhaps the view can use them $view = $CI->load->view("_blocks/".$p['view'], $vars, TRUE); } } else if (file_exists($view_file)) { // pass along these since we know them... perhaps the view can use them $view = $CI->load->view("_blocks/".$p['view'], $vars, TRUE); } } // parse the view again to apply any variables from previous parse $output = ($p['parse'] === TRUE) ? $CI->parser->parse_string($view, $vars, TRUE) : $view; if ($p['cache'] === TRUE) { $CI->cache->save($cache_id, $output, $cache_group, $CI->config->item('page_cache_ttl', 'fuel')); } return $output; }
/** * Allows you to load a view and pass data to it * * Renders a navigation structure using the <a href="[user_guide_url]libraries/menu">Menu class</a>. * * The <a href="[user_guide_url]helpers/fuel_helper">fuel_block helper</a> function is an alias to this method. * <ul> <li><strong>view</strong> - the name of the view block file. Also can be the first parameter of the method</li> <li><strong>vars</strong>: an array of variables to pass to the block. Also can be the second parameter of the method.</li> <li><strong>scope</strong>: a string value used for placing the variables into a certain scope to prevent conflict with other loaded variables. Default behavior will load variables in to a global context. The value of TRUE will generate one for you.</li> <li><strong>view_string</strong> - a string variable that represents the block</li> <li><strong>model</strong> - the name of a model to automatically load for the block</li> <li><strong>find</strong> - the name of the find method to run on the loaded model</li> <li><strong>select</strong> - select parameters to run for the find method</li> <li><strong>where</strong> - where parameters to run for the find method</li> <li><strong>order</strong> - the order the find method should return</li> <li><strong>limit</strong> - the limit number of results to be returned by the find method</li> <li><strong>offset</strong> - the find results returned offset value</li> <li><strong>return_method</strong>: the return method the find query should use</li> <li><strong>assoc_key</strong>: the column name to be used as the associative key in the find method</li> <li><strong>data</strong>: the data values to be passed to the block. This variable get's automatically set if you specify the model and find method</li> <li><strong>editable</strong>: css class styles to apply to menu items... can be a nested array</li> <li><strong>parse</strong>: determines whether to parse the contents of the block. The default is set to 'auto'</li> <li><strong>cache</strong>: determines whether to cache the block. Default is false</li> <li><strong>mode</strong>: explicitly will look in either the CMS or the views/_blocks folder</li> <li><strong>module</strong>: the name of the module to look in for the block</li> <li><strong>language</strong>: the language version to use for the block. Must be a value specified found in the 'languages' options in the FUEL configuration</li> <li><strong>use_default</strong>: determines whether to find a non-language specified version of a block with the same name if the specified language version is not available in the CMS</li> </ul> * @access public * @param mixed Array of parameters * @param array Array of variables * @param boolean Determines whether to check the CMS for the block or not (alternative to using the "mode" parameter) * @param boolean Determines whether to scope the variables. A string can also be passed otherwise the scope value will be created for you * @return string */ public function render($params, $vars = array(), $check_db = TRUE, $scope = NULL) { $this->CI->load->library('parser'); $valid = array('view' => '', 'view_string' => FALSE, 'model' => '', 'find' => 'all', 'select' => NULL, 'where' => '', 'order' => '', 'limit' => NULL, 'offset' => 0, 'return_method' => 'auto', 'assoc_key' => '', 'data' => array(), 'editable' => TRUE, 'parse' => 'auto', 'vars' => array(), 'scope' => $scope, 'cache' => FALSE, 'mode' => 'auto', 'module' => '', 'language' => NULL, 'use_default' => TRUE); // for convenience if (!is_array($params)) { $new_params = array(); if (strpos($params, '=') === FALSE) { $new_params['view'] = $params; } else { $this->CI->load->helper('array'); $new_params = parse_string_to_array($params); } $params = $new_params; } $p = array(); foreach ($valid as $param => $default) { $p[$param] = isset($params[$param]) ? $params[$param] : $default; } // pull from cache if cache is TRUE and it exists if ($p['cache'] === TRUE) { $this->CI->load->library('cache'); $cache_group = $this->CI->fuel->config('page_cache_group'); $cache_id = !empty($p['view_string']) ? $p['view_string'] : $p['view']; $cache_id = md5($cache_id); $cache = $this->CI->cache->get($cache_id, $cache_group); if (!empty($cache)) { return $cache; } } // load the model and data $p['vars'] = (array) $p['vars']; $vars = (is_array($vars) and !empty($vars)) ? array_merge($p['vars'], $vars) : $p['vars']; if (!empty($p['model'])) { $data = fuel_model($p['model'], $p); $module = $this->CI->fuel->modules->get($p['model']); if ($module) { $model_name = $module->model()->friendly_name(TRUE); if (!empty($model_name)) { $var_name = $module->model()->friendly_name(TRUE, FALSE); $vars[$var_name] =& $data; // for convenience $vars['data'] =& $data; } } } else { $vars['data'] = $p['data']; } $output = ''; // load proper view to parse. If a view is given then we first look up the name in the DB $view = ''; if (!empty($p['view_string'])) { $view = $p['view_string']; } else { if (!empty($p['view'])) { $is_module_block = FALSE; $view_path = 'views/_blocks/'; if (!empty($p['module']) and defined('MODULES_PATH')) { if ($p['module'] == 'app' or $p['module'] == 'application') { $view_path = APPPATH . $view_path; } else { $view_path = MODULES_PATH . $p['module'] . '/' . $view_path; } $is_module_block = TRUE; } else { $view_path = APPPATH . $view_path; } // get language value if ($this->fuel->language->has_multiple()) { $language = !empty($p['language']) ? $p['language'] : $this->fuel->language->detect(); } else { $language = $this->fuel->language->default_option(); } // test that the file exists in the associated language if (!empty($language) and !$this->fuel->language->is_default($language)) { $view_tmp = 'language/' . $language . '/' . $p['view']; if (file_exists($view_path . $view_tmp . EXT)) { $view_file = $view_path . $view_tmp . EXT; } } if (empty($view_file)) { $view_file = $view_path . $p['view'] . EXT; } $p['mode'] = strtolower($p['mode']); // only check database if the fuel_mode does NOT equal 'views, the "only_views" parameter is set to FALSE and the view name does not begin with an underscore' if ($check_db and ($p['mode'] == 'auto' and $this->mode() != 'views' or $p['mode'] == 'cms') and substr($p['view'], 0, 1) != '_') { $this->fuel->load_model('fuel_blocks'); // find the block in FUEL db $block = $this->CI->fuel_blocks_model->find_one_by_name_and_language($p['view'], $language); // if there is no block found with that language we will try to find one that may not have a language associated with it if (!isset($block->id) and $p['use_default']) { $block = $this->CI->fuel_blocks_model->find_one_by_name($p['view']); } if (isset($block->id)) { if (strtolower($p['parse']) == 'auto') { $p['parse'] = TRUE; } $view = $block->view; if ($p['editable'] === TRUE) { $view = fuel_edit($block->id, 'Edit Block: ' . $block->name, 'blocks') . $view; } } else { if (file_exists($view_file)) { // pass in reference to global CI object $vars['CI'] =& $this->CI; // pass along these since we know them... perhaps the view can use them $view = $is_module_block ? $this->CI->load->module_view($p['module'], '_blocks/' . $p['view'], $vars, TRUE, $p['scope']) : $this->CI->load->view('_blocks/' . $p['view'], $vars, TRUE, $p['scope']); } } } else { if (file_exists($view_file)) { // pass in reference to global CI object $vars['CI'] =& $this->CI; // pass along these since we know them... perhaps the view can use them $view = $is_module_block ? $this->CI->load->module_view($p['module'], '_blocks/' . $p['view'], $vars, TRUE, $p['scope']) : $this->CI->load->view('_blocks/' . $p['view'], $vars, TRUE, $p['scope']); } } } } // parse the view again to apply any variables from previous parse $output = $p['parse'] === TRUE ? $this->CI->parser->parse_string($view, $vars, TRUE) : $view; if ($p['cache'] === TRUE) { $this->CI->cache->save($cache_id, $output, $cache_group, $this->CI->fuel->config('page_cache_ttl')); } return $output; }
<?php //$CI->load->module_view('app', '_install') ?> <?php echo fuel_set_var('layout', ''); ?> <?php $this->load->view('_blocks/header'); ?> <?php $posts = fuel_model('blog_posts', array('find' => 'all', 'limit' => 3, 'order' => 'sticky, date_added desc', 'module' => 'blog')); if (!empty($posts)) { ?> <h2>The Latest from our Blog</h2> <ul> <?php foreach ($posts as $post) { ?> <li> <h4><a href="<?php echo $post->url; ?> "><?php echo $post->title; ?> </a></h4> <?php