I use CakePHP 2.5.5 . My project in this directory: C:\xampp\htdocs\vy\cakephp-2.5.5 . My project directory layout:
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\Model\task.php (Model)with content:
<?php
class Task extends AppModel
{
var $name = 'Task';
}
?>
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\Controller\TasksController.php (Controller) with content:
<?php
class TasksController extends AppController
{
var $name = 'Tasks';
function index()
{
$this->set('tasks', $this->Task->find('all'));
}
}
?>
I have been created file C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Task\index.ctp (View) with content:
<h2>Tasks</h2>
<?php if (empty($tasks)): ?>
There are no tasks in this list
<?php else : ?>
<table>
<tr>
<th>Title</th>
<th>Status</th>
<th>Created</th>
<th>Modified</th>
<th>Actions</th>
</tr>
<?php foreach ($tasks as $task): ?>
<tr>
<td>
<?php echo $task['Task']['title'] ?>
</td>
<td>
<?php
if ($task['Task']['done']) echo "Done";
else echo "Pending";
?>
</td>
<td>
<?php echo $task['Task']['created'] ?>
</td>
<td>
<?php if ($task['Task']['modified']) ?>
</td>
<td>
<!-- actions on tasks will be added later -->
</td>
</tr>
<?php endforeach; ?>
</table>
<?php endif; ?>
When run program, error:
Missing View
Error: The view for TasksController::index() was not found.
Error: Confirm you have created the file: C:\xampp\htdocs\vy\cakephp-2.5.5\app\View\Tasks\index.ctp
Notice: If you want to customize this error message, create app\View\Errors\missing_view.ctp
How to repair above application? Thank you!
All you have to do is read the error message carefully :)
The view folder should be View\Tasks (plural) instead of View\Task as you currently have.
Also your model file name should be Task.php not task.php. Be carefully of case sensitivity in file names. While things will work on windows if you move files to a linux server you will get errors as it has case sensitive filesystem.
Related
I am fetching data from database and trying to display it in a view but it does not work. However, print_r outputs the data successfully.
Model:
<?php
class Usermodel Extends CI_model{
public function getUserdata()
{
$this->load->database();
// $q=$this->db->select('name');
$q=$this->db->get('user');
return $q->result_array();
}
}
?>
Controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Users extends CI_controller{
public function User(){
$this->load->model('Usermodel');
$data['users']=$this->Usermodel->getUserdata();
$this->load->view('Users/userlist',$data);
}
}
?>
View:
<!DOCTYPE html>
<html lang="en">
<head>
<title>User Details</title>
</head>
<body>
<br>
<?php print_r($users); ?>
<h1>User Account Details</h1>
<tr>
<td>First Name</td>
<td>Account No</td>
</tr>
<?php foreach($users as $users): ?>
<tr>
<td><?php $users['name']; ?></td>
<td><?php $users['accountnumber']; ?></td>
</tr>
<?php endforeach ?>
</body>
</html>
You must use either echo construct or short echo tag in your view. Short echo tag is more preferred as it is more concise. For example: <?= $users['name'] ?>
In your code you just return the value of variables to nowhere instead of printing it out so the result is not showing.
You should use echo .
For your code example write <td><?php echo $users['name']; ?></td>
Hi im new to using additional libraries on codeigniter (im using this library) so these error are really overwhelming me, the goal im trying is to make a form input with option tag (the options from my db) then when i click the button, it will automatically generate the qrcode. at first im following some tutorial from the internet and adjust some parts in order to reach the actual goal.
It doesnt show any explicit error on the html page so i checked the console of the page the error as follows;
jquery-3.4.1.js:9837 POST http://localhost/ikanku/Make_qr/save 500 (Internal Server Error)
send # jquery-3.4.1.js:9837
ajax # jquery-3.4.1.js:9434
(anonymous) # make_qr:421
dispatch # jquery-3.4.1.min.js:2
v.handle # jquery-3.4.1.min.js:2
so im trying to open the network tab to see if there anything that i could fix anything, but it confuse me bcs the error show as following;
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Make_qr::$Ciqrcode
Filename: core/Model.php
Line Number: 73
Backtrace:
File: C:\xampp\xampp\htdocs\ikanku\application\models\Make_qr_model.php
Line: 35
Function: __get
File: C:\xampp\xampp\htdocs\ikanku\application\controllers\Make_qr.php
Line: 24
Function: save
File: C:\xampp\xampp\htdocs\ikanku\index.php
Line: 315
Function: require_once
ive been load the model name, controllers name globally through the autoload and internally through parent::__construct(); but it still error as above, i really need anyone's suggestion/advice for my problem because im still learning on how to make a qrcode feature in my application.
Right now im using CodeIgniter 3.1.11
heres my controller - Make_qr.php
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Make_qr extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('Make_qr_model');
}
public function index()
{
$data['vessel'] = $this->db->query('select * from vessel order by vessel_name')->result_array();
$data['port'] = $this->db->query('select * from port order by port_name')->result_array();
$this->load->view('template/header');
$this->load->view('template/sidebar');
$this->load->view('qrcode/make_qr',$data);
$this->load->view('template/footer');
}
public function save()
{
$this->Make_qr_model->save($this->input->post());
}
}
heres my model - Make_qr_model.php
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');
class Make_qr_model extends CI_Model {
function __construct()
{
parent::__construct();
$this->load->library('Ciqrcode');
}
function random_strings($length_of_string){
$str_result = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; //abcdefghijklmnopqrstuvwxyz
return substr(str_shuffle($str_result),0, $length_of_string);
}
//save data function setelah qrcode di generate
public function save($data){
$data = array_replace($data,
array_fill_keys(
array_keys($data, ""),
NULL
)
);
if(isset($data['quantity']) && count($data['quantity'])>0){
for($i=1;$i<=$data['quantity'];$i++){
$r = $this->random_strings(6);
$this->load->library('Ciqrcode');
$config['cacheable'] = true;
$config['cachedir'] = './assets/';
$config['errorlog'] = './assets/';
$config['imagedir'] = './assets/images/';
$config['quality'] = true;
$config['size'] = '1024';
$config['black'] = array(224,255,255);
$config['white'] = array(70,130,180);
$this->Ciqrcode->initialize($config);
$image_name=$r.'.png'; //buat name dari qr code sesuai dengan random string
$params['data'] = $r; //data yang akan di jadikan QR CODE
$params['level'] = 'H'; //H=High
$params['size'] = 1024;
$params['savename'] = FCPATH.$config['imagedir'].$image_name; //simpan image QR CODE ke folder assets/images/
$this->Ciqrcode->generate($params); // fungsi untuk generate QR CODE
$img = file_get_contents(FCPATH.$config['imagedir'].$image_name, "r");
$base64 = 'data:image/png;base64,'.base64_encode($img);
$data_insert = array();
$data_insert['vessel_id'] = $data['vessel_id'];
$data_insert['port_id'] = $data['port_id'];
$data_insert['key'] = $r;
$data_insert['qr'] = $base64;
$this->db->insert('qr_vessel', $data_insert);
$vessel = $this->db->query('select * from vessel where id='.$data['vessel_id'])->row_array();
echo "<table class='table table-striped m-table'>
<tbody>
<tr>
<td width='30%' style='background-color:black'>
<img src=".$base64.">
</td>
<td width='70%' style='vertical-align:top'>
Vessel Name : ".$vessel['vessel_name']."<br>
Vessel Company : ".$vessel['company']."<br>
Fishing Gear : ".$vessel['fishing_gear']."<br>
</td>
</tr>
<tr>
<td align='center'>
".$r."
</td>
<td align='center'></td>
</tr>
</body>
</table>";
}
$notif['x'] = 'ok';
}else{
$notif['x'] = 'error';
die('error');
}
return;
}
}
?>
and heres my view - make_qr.php
<section class="content">
<form role="form" name="frm" action="<?=site_url('Make_qr/save')?>" method="post" id="frm">
<div id="container">
<h1>Generate Fishing QR</h1>
<div id="body">
<table class="table table-striped m-table">
<tbody>
<tr>
<td>Vessel</td>
<td>
<select id='vessel_id' name='vessel_id' style="width:250px" >
<option value="">Pilih</option>
<?php
foreach($vessel as $row){
?>
<option value="<?=$row['id_vessel']?>"><?=$row['vessel_name']?> - <?=$row['company']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>Port Departure</td>
<td>
<select id='port_id' name='port_id' style="width:250px" >
<option value="">Pilih</option>
<?php
foreach($port as $row){
?>
<option value="<?=$row['id_port']?>"><?=$row['port_name']?></option>
<?php
}
?>
</select>
</td>
</tr>
<tr>
<td>QR Quantity</td>
<td>
<select id='quantity' name='quantity'>
<option value="">Pilih</option>
<?php
for($i=1;$i<=20;$i++){
?>
<option value="<?=$i?>"><?=$i?></option>
<?php
}
?>
</select>
</td>
</tr>
</tbody>
</table>
<div class="col-lg-3 m--margin-bottom-10-tablet-and-mobile">
<span id='loading' style="display:none"><img src="<?php echo base_url(); ?>Assets/assets/images/ajax-loader_dark.gif"></span>
<button type="button" class="btn btn-info" id="save">Generate</button>
</div>
<br>
<div id='qrs'></div>
</div>
</section>
i apologize for the long description of my errors it would be mean so much to me if i can get some advice & suggestion from here,
thankyou
Change model name Make_qr_model to Makeqr_model
Load library $this->load->model('Makeqr_model');
Load CodeIgniter-PHP-QR-Code library properly; clone git repo and paste folder inside application/libraries
Make sure GD2 PHP extension installed
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class QRGenerator extends CI_Controller {
function __construct(){
Parent::__construct();
}
public function generate(){
$this->load->library('ciqrcode');
$params['data'] = 'This is a text to encode become QR Code';
$params['level'] = 'H';
$params['size'] = 10;
$params['savename'] = FCPATH.'tes.png';
$this->ciqrcode->generate($params);
echo '<img src="'.base_url().'test.png" />';
}
}
Codeigniter model reference click
Hope it will help you
I'm developing a MVC component for Joomla! 2.5 and I want to add some sortable columns in my backend. For this goal I've tried to do the next:
http://docs.joomla.org/Adding_sortable_columns_to_a_table_in_a_component
And I got an error "View not found [name, type, prefix]". In this case I have looking for a solution and I find the next:
http://forum.joomla.org/viewtopic.php?p=2638695
Following those indications I have removed the "action" of my "form". In this case my column is sortable, but another problem arises. If I remove the "action" of my "form" then "edit buttom" of my toolbar does not work.
I think there must be another solution because I need working "edit buttom" and sortable column also. I've looking for some similar question here and I've applied the following information:
How to add sortable columns in a Joomla component (table), both ASC and DESC with an arrow
&
Joomla 2.5 -Adding sortable columns to a table in a component
But my problem persits. What can I do?? Thank you.
MY RELEVANT SOURCE CODE IS THE NEXT:
com_inscripciones/admin/models/anuals.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import the Joomla modellist library
jimport('joomla.application.component.modellist');
/**
* Inscripciones List Model
*/
class InscripcionesModelAnuals extends JModelList
{
public function __construct($config = array())
{
if (empty($config['filter_fields'])) {
$config['filter_fields'] = array(
'nombre',
'fecha_nac',
'reserva'
);
}
parent::__construct($config);
}
protected function populateState($ordering = null, $direction = null)
{
parent::populateState('id', 'asc');
}
/**
* Method to build an SQL query to load the list data.
*
* #return string An SQL query
*/
protected function getListQuery()
{
// Create a new query object.
$db = JFactory::getDBO();
$query = $db->getQuery(true);
// Select some fields
$query->select('id,nombre,apellidos,nif,fecha_nac,reserva,validacion,clave');
// From the hello table
$query->from('#__anual');
// Add the list ordering clause.
$query->order($db->escape($this->getState('list.ordering', 'nombre')).' '.$db->escape($this->getState('list.direction', 'ASC')));
return $query;
}
}
?>
com_inscripciones/admin/views/anuals/view.html.php
<?php
// No direct access to this file
defined('_JEXEC') or die('Restricted access');
// import Joomla view library
jimport('joomla.application.component.view');
/**
* Anuals View
*/
class InscripcionesViewAnuals extends JView
{
/**
* display method of Inscripciones view
* #return void
*/
function display($tpl = null)
{
// Get data from the model
$items = $this->get('Items');
$pagination = $this->get('Pagination');
$state = $this->get('State');
$this->sortDirection = $state->get('list.direction');
$this->sortColumn = $state->get('list.ordering');
// Check for errors.
if (count($errors = $this->get('Errors')))
{
JError::raiseError(500, implode('<br />', $errors));
return false;
}
// Assign data to the view
$this->items = $items;
$this->pagination = $pagination;
// Set the toolbar
$this->addToolBar();
// Display the template
parent::display($tpl);
}
/**
* Setting the toolbar
*/
protected function addToolBar()
{
JToolBarHelper::title(JText::_('Inscripciones Manager: Curso Anual'), 'inscripciones');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::editList('anual.edit');
JToolBarHelper::spacer('10');
JToolBarHelper::divider();
JToolBarHelper::spacer('10');
JToolBarHelper::deleteList('¿Desea eliminar esta inscripción?', 'anuals.delete');
JToolBarHelper::spacer('20');
}
}
?>
com_inscripciones/admin/views/anuals/tmpl/default.php
<?php
// No direct access
defined('_JEXEC') or die('Restricted access');
JHtml::_('behavior.tooltip');
JHtml::_('behavior.multiselect');
?>
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>"method="post" name="adminForm"id="inscripciones-form">
<table class="adminlist">
<thead>
<tr>
<th width="5">
<?php echo JText::_('ID'); ?>
</th>
<th width="20">
<input type="checkbox" name="toggle" value="" onclick="checkAll(<?php echo count($this->items); ?>);" />
</th>
<th>
<?php echo JHtml::_('grid.sort', 'NOMBRE', 'nombre', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JText::_('APELLIDOS'); ?>
</th>
<th>
<?php echo JText::_('NIF'); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'FECHA NAC.', 'fecha_nac', $this->sortDirection, $this->sortColumn); ?>
</th>
<th>
<?php echo JHtml::_('grid.sort', 'RESERVA', 'reserva', $this->sortDirection, $this->sortColumn); ?>
</th>
</tr>
</thead>
<tfoot>
<tr>
<td colspan="3"></td>
</tr>
</tfoot>
<tbody>
<?php foreach ($this->items as $i => $item): ?>
<tr class="row<?php echo $i % 2; ?>">
<td>
<?php echo $item->id; ?>
</td>
<td>
<?php echo JHtml::_('grid.id', $i, $item->id); ?>
</td>
<td>
<?php echo $item->nombre; ?>
</td>
<td>
<?php echo $item->apellidos; ?>
</td>
<td>
<?php echo $item->nif; ?>
</td>
<td>
<?php echo $item->fecha_nac; ?>
</td>
<td>
<?php echo $item->reserva; ?>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<div>
<input type="hidden" name="task" value="" />
<input type="hidden" name="boxchecked" value="0" />
<input type="hidden" name="filter_order" value="<?php echo $this->sortColumn; ?>" />
<input type="hidden" name="filter_order_Dir" value="<?php echo $this->sortDirection; ?>" />
<?php echo JHtml::_('form.token'); ?>
</div>
My query line in model looks like
$query->order($db1->getEscaped($this->getState('list.ordering', 'ordering')).' '.$db1->getEscaped($this->getState('list.direction', 'ASC')));
and populateState contains
$orderCol = JRequest::getCmd('filter_order', 'ordering');
$this->setState('list.ordering', $orderCol);
and the construct on the filter_fields contains
$this->_order[] = JRequest::getVar('filter_order', 'fieldName', 'POST', 'cmd');
$this->_order[] = JRequest::getVar('filter_order_Dir', 'asc', 'POST', 'word');
I had some trouble getting these working in some views in a component I made, just a lot of combinations of things that can be wrong, but you'll get there. I used this tutorial
http://docs.joomla.org/J2.5:Developing_a_MVC_Component/Introduction
I guess you have already found the bug, but for everyone else, based on the provided code:
<form action="<?php echo JRoute::_('index.php?option=com_inscripciones&view=anuals$layout=default'); ?>" ...>
This line is wrong. Your view call is &view=anuals$layout=default.
Correct would be &view=anuals&layout=default
The only reason why you got that view error.
Please mark my answer as correct if that was you problem back in 2014.
Using CodeIgniter I am trying to create a link that the user can click within a view to show them the details of a record in my database.
In ASP.NET MVC3 with C# I would do it with #Html.ActionLink("Controller", "Action", new { id = item.Id})
This is my session controllers index() function
public function index()
{
$data['sessions'] = $this->session_model->get_sessions();
$this->load->view('_header');
$this->load->view('session/index', $data);
$this->load->view('_footer');
}
This is the index view it loads where I want to be able to click the link to go to enter() function
<table>
<th>Session Name</th>
<th>Description</th>
<th>Host</th>
<th></th>
<?php foreach ($sessions as $session_item): ?>
<tr>
<td> <?php echo $session_item['sessionName'] ?> </td>
<td> <?php echo $session_item['sessionDesc'] ?> </td>
<td> <?php echo $session_item['adminName'] ?> </td>
<td> <a id="enterSession" href=<?php echo site_url("session/enter" + $session_item['id']) ?> >Enter</a></td>
</tr>
<?php endforeach ?>
The enter session points me to the url "http://192.168.1.36/index.php/1" (if the id of my item is 1) whereas I expect "http://192.168.1.36/index.php/session/enter/1"
Any ideas on how I can make it call the enter() function also in the session controller (shown below)
public function enter($id) {
$this->load->view('_header');
$this->load->view('session/enter');
$this->load->view('_footer');
}
There seems to be a typo in the string concatenation in your PHP code. Perhaps it will work to use:
site_url("session/enter" . $session_item['id'])
... rather than a + sign between the two strings.
Regarding the second question - it looks correct as-is. Is it failing to call the session controller's enter() function passing the $id as an argument (assuming the URL is correct)?.
i am trying to implement jquery datatable, in my cakePHP based website, but it just wont load. this website is already half developed, and from the way i see it, the js' is loaded through a file called _head.inc.ctp located inside the views/layouts folder, i have added the datatables library inside the libs folder which is webroot/js/libs and load it inside the _head.inc.ctp file.
suppose i have this:
my controller:
var $helpers = array(
'Form',
'Html',
'Javascript'
);
//my method
function dataTable_example($id=null){
$details = $this->Detail->find("all");
$this->set('details', $details );
}
my view:
<div>
<?php echo $javascript->link('libs/jquery.dataTables.js'); ?>
<script>
$(document).ready(function(){
$('#js-datatable').dataTable();
});
</script>
<h2><?php echo __l('Tickets');?></h2>
<div>
<table id="js-datatable">
<tr>
<th>some heading 1</th>
<th>some heading 1</th>
<th>some heading 1</th>
</tr>
<?php
if (!empty($details)){
foreach ($details as $detail):
?>
<tr>
<td><?php echo $detail['Detail']['id'];?></td>
<td><?php echo $detail['Detail']['created'];?></td>
<td><?php echo $detail['Detail']['ticket_detail'];?></td>
</tr>
<?php
endforeach;
}else{
?>
<tr>
<td>No Data Found</td>
</tr>
<?php }?>
</table>
</div>
</div>
i even hard coded it using the usual call, and checked it using firebug to see if the script is loaded or not, and according to firebug, it is loaded, so i cant see whats making the script fail my table.
did i missed some steps ? please help
thanks
You don't have thead and tbody elements as required by the datatables script
You should use the find function in your controller and pass the array to the view and in the view write it.. don't just leave the table empty