Inline editing question

edited April 2012 in Installation
Another question from me. I have been reading all the tutorials and the user guide but I still have a question about inline editing.
I set up a very simple site with a MVC structure. I tried to do it in the 'normal CI way' just for myself to keep it understandable. I know that you can save code lines with using for example fuel_model(), but that is something for later.
I have a model (and added it to my_fuel_modules) that gets some data from a db:

<?php if (!defined('BASEPATH')) exit('No direct script access allowed'); require_once(FUEL_PATH.'models/base_module_model.php'); class Headlines_model extends Base_module_model { function __construct() { parent::__construct('test'); // table name } function list_items($limit = NULL, $offset = NULL, $col = 'tekst', $order = 'desc') { $this->db->select('id, tekst, published'); $data = parent::list_items($limit, $offset, $col, $order); return $data; } } class Headlines2_model extends Base_module_record { }

Than I have a controller that passes this data onto the view:

<?php class Testcontrol extends CI_Controller { function __construct() { parent::__construct(); $this->load->model('headlines_model'); } function index() { $vars['test'] = $this->headlines_model->find_all(); $this->load->view('testview', $vars); } }

and the view file:
<html> <head> <title>Title</title> </head> <body> <h1>Test</h1> <p>Hallo dit is een testsite. Dit is een view die aan wordt geroepen door een controller</p> <?php foreach ($test as $value): ?> <?php echo fuel_edit($value['id'], 'Change news item', 'headlines'); ?> <h1><?php echo $value['tekst'] ?></h1> <?php endforeach ?> </body> </html>

Okay so far everything good. When I go to index.php/testcontrol I can see my database entries. The question is how do I make the view inline editable. I added the fuel_edit() function but that did not help.
As you can see I did not use the layout files. Because the functionality is still quite vague for me. I have read that the layouts define the editable areas, however in the tutorial (widget corp) main layout I cannot find this because I only see fuel_edit() in the view files. I think this is where something goes wrong.

My last question is: what is the correct way of going from the dashboard to a page that is based on a module for inline editing, because you only see the modules in the dashboard but you can not view the page that uses the module. I hope it is clear what I mean. Fixed this by adding a preview path to MY_fuel_modules.

Comments

  • edited April 2012
    A little update.
    I created a layout file that inserts a header footer and the $body. So I removed all the tags etc from my view file.

    If I add the view file as a page in the dashboard the php foreach loop doesn't show the results if I click the 'view button'. However if I use:
    <?php $quotes = fuel_model('headlines', array('find' => 'all')); ?>
    and use the quotes variables in the foreach loop than the database entries do show and they are editable. But I still don't get the view button if I go to the headlines module in the dashboard. Apparently doing it with 'normal codeigniter' way I miss some page variables. I hope someone can explain this a little.

    How do others do it for there clients? Do you let them only change the module (in the dashboard), because if you add a page than they can get really confused by the php that shows in the edit field.

    EDIT:
    I finished the Tutorial: Creating Simple Modules. And here I have the same problem as described above. In the last alinea it is explained how to add inline editing. However how do I get there if I am at the dash board. If I add the preview path of the articles module and direct it to example.php I can go and view the page but there is no pencil or even a toolbar display. I am 100 percent sure that I followed the tutorial right, so what am I doing wrong?
  • edited 1:43PM
    For inline editing to work, it needs to be rendered by the Fuel_page class. If you are using a controller, then instead of using $this->load->view('testview', $vars);, you need to use the following:
    $page_init = array('location' => 'testview'); $this->load->module_library(FUEL_FOLDER, 'fuel_page', $page_init); $this->fuel_page->add_variables($vars); $this->fuel_page->render();
    If you look at the contact controller in the demo site, you'll see something similar.

    Pages created in the admin or through using the "opt-in controller" method automatically use the Fuel_page class to render the page. More can be found here:
    http://www.getfuelcms.com/user_guide/general/opt-in-controllers
  • edited April 2012
    Thanks a lot for again you quick and to the point answer. Even though I had read this many I only realised the real meaning after your post (all the information is quite overwhelming for me).

    I have another question concerning the creating simple modules tutorial. I post it here because I don't want to open a new discussion all the time.

    in the 'polishing' section they make a function so that you can upload a picture. For this the following code is used:

    class Author_model extends Data_record { public function get_avatar_image() { return '<img src="'.img_path($this->avatar).'" />'; } }

    my question is how do I use this function. When I log in the view file (with chromephp):

    $CI->load->model('articles_model'); ChromePhp::log($CI->authors_model);
    EDIT
    Okay obviously you can get the method like this:
    <?=$article->author->avatar_image?>

    I cannot find it as a method. Found it.

    My question still remains why I can't find the methods from the table class (like find_all() for example)?
  • edited 1:43PM
    The methods like find_all, find_one, etc, belong to the table class. You can use the "fuel_model" function in the front end to get your objects or you can reference the model itself like so:
    $articles = fuel_model('articles', array('find' => 'all')); foreach($articles as $article): echo $article->title; endforeach;
    $CI->load->model('articles_model'); $articles = $CI->articles_model->find_all(); foreach($articles as $article): echo $article->title; endforeach;
    More on the fuel_model can be found here:
    http://www.getfuelcms.com/user_guide/helpers/fuel_helper

    More on the model stuff can be found here:
    http://www.getfuelcms.com/user_guide/libraries/my_model

    Within your record object (e.g. $article), there is a protected property of _parent_model which references the parent Articles_model and can be used in your record classes method's. So for example, if you added a property of "avatar_img_paths" to the Authors_model table class like so:
    class Authors_model extends Base_module_model { public $avatar_img_paths = 'avatars/'; ...... }
    You could access it from your record class like so:
    class Author_model extends Data_record { public function get_avatar_image() { $img_path = $this->_parent_model->avatar_img_paths; return '<img src="'.img_path($this->avatar).'" />'; } }
Sign In or Register to comment.