It looks like you're new here. If you want to get involved, click one of these buttons!
<?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 {
    
}
<?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);		
}
}
<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>
Comments
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?
$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
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)?
$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).'" />'; } }