I am using Eclipse for PHP (PDT) Helios, how to auto format CakePHP Template file? For example: when I follow this tutorial , when I edit file index.ctp like this:
<!-- File: /app/View/Posts/index.ctp -->
<h1>Blog posts</h1>
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Created</th>
</tr>
<!-- Here is where we loop through our $posts array, printing out post info -->
<?php foreach ($posts as $post): ?>
<tr>
<td><?php echo $post['Post']['id']; ?></td>
<td>
<?php echo $this->Html->link($post['Post']['title'],
array('controller' => 'posts', 'action' => 'view', $post['Post']['id'])); ?>
</td>
<td><?php echo $post['Post']['created']; ?></td>
</tr>
<?php endforeach; ?>
<?php unset($post); ?>
</table>
I don't undestand how Eclipse autoformat above snippet code. Please help me, thank you!
In Aptana Studio (is based on Eclipse) try this:
Window / Preferences / General / Editors / File Associations
If You haven't .ctp file, You must add it, after add to this extension Assiociated files to PHP
I do this like my follow screenshot:
Related
OK guys, I have a page with a dinamic table using jquery datatables
<div class="widget">
<div class="widget-head">
<h5>Usuarios</h5>
</div>
<div class="widget-body">
<div class="row">
<div class="col-md-12">
<div class="table-responsive">
<table cellpadding="0" cellspacing="0" border="0" id="data-table" width="100%">
<thead>
<tr>
<th><?php echo lang('index_fname_th');?></th>
<th><?php echo lang('index_lname_th');?></th>
<th><?php echo lang('index_email_th');?></th>
<th><?php echo lang('index_groups_th');?></th>
<th><?php echo lang('index_code_th');?></th>
<th><?php echo lang('index_status_th');?></th>
<th><?php echo lang('index_action_th');?></th>
<th><?php echo lang('index_net_th');?></th>
</tr>
</thead>
<tbody>
<?php foreach ($users as $user):?>
<tr>
<td><?php echo htmlspecialchars($user->first_name,ENT_QUOTES,'UTF-8');?></td>
<td><?php echo htmlspecialchars($user->last_name,ENT_QUOTES,'UTF-8');?></td>
<td><?php echo htmlspecialchars($user->email,ENT_QUOTES,'UTF-8');?></td>
<td>
<?php foreach ($user->groups as $group):?>
<?php echo anchor("auth/edit_group/".$group->id, htmlspecialchars($group->name,ENT_QUOTES,'UTF-8')) ;?><br />
<?php endforeach?>
</td>
<td><?php echo htmlspecialchars($user->codigo,ENT_QUOTES,'UTF-8');?></td>
<td><?php echo ($user->active) ? anchor("auth/deactivate/".$user->id, lang('index_active_link')) : anchor("auth/activate/". $user->id, lang('index_inactive_link'));?></td>
<td><?php echo anchor("auth/edit_user/".$user->id, 'Edit') ;?></td>
<td><?php echo htmlspecialchars($user->red,ENT_QUOTES,'UTF-8');?></td>
</tr>
<?php endforeach;?>
</tbody>
<tfoot>
<tr>
<th><?php echo lang('index_fname_th');?></th>
<th><?php echo lang('index_lname_th');?></th>
<th><?php echo lang('index_email_th');?></th>
<th><?php echo lang('index_groups_th');?></th>
<th><?php echo lang('index_code_th');?></th>
<th><?php echo lang('index_status_th');?></th>
<th><?php echo lang('index_action_th');?></th>
<th><?php echo lang('index_net_th');?></th>
</tr>
</tfoot>
</table>
</div>
</div>
</div>
</div>
<div class="widget-foot">
</div>
</div>
edit:
this is my js script:
/* Data Table */
/* ********** */
$(document).ready(function() {
$('#data-table').dataTable({
"sPaginationType": "full_numbers",
"dom": 'T<"clear">lfrtip'
});
});
/* ****************************** */
and my css is the big file you download from datatables web page.
I have spent almost a week trying to add tabletools to my code i just cant understand the documentation, can anyone point me in the right direction please.
Thanks everyone!
first import the data tabletools package
after that unzipped the folder where the your project folder
after that include the source file
like this
<script src="http://localhost:88/project_name/DataTables-1.10.7/media/js/jquery.js"></script>
<script src="http://localhost:88/project_name/DataTables-1.10.7/media/js/jquery.dataTables.js"></script>
<script src="http://localhost:88/project_name/DataTables-1.10.7/extensions/TableTools/js/dataTables.tableTools.min.js"></script>
<link href="http://localhost:88/project_name/DataTables-1.10.7/media/css/jquery.dataTables.css"rel="stylesheet">
<link href="http://localhost:88/project_name/DataTables-1.10.7/extensions/TableTools/css/dataTables.tableTools.css"rel="stylesheet">
and after that
include the jquery function
<script>
$(document).ready(function() {
$('#index1').DataTable( {
dom: 'T<"clear">lfrtip',
tableTools: {
"sSwfPath": "http://localhost:88/project_name/DataTables1.10.7/extensions/TableTools/swf/copy_csv_xls.swf"
}
} );
} );
</script>
here index1 is table id
Ok.
Table tools are a PLUGIN to datatables, a number of steps are required to get this to work.
I cannot see your header, so I do not know what you have included (js,css)
First you need to have all the scripts/css for the standard data tables.
In addition to that you need to go https://www.datatables.net/extensions/tabletools/plug-ins and download/save the javascript and add that to your header to be loaded, you also need to download, save and load the table tools css sheet in your header as well - again I cannot see that you have done so.
Go to https://www.datatables.net/release-datatables/extensions/TableTools/examples/simple.html, save all the HTML/JS/CSS locally and create a file to test that locally. Once that is working with external files start including the files (js/css) on your server - if its still working you know you have all the required libraries.
Then try your code - if it does not work put a SIMPLE table in their - you could even use the one from the table tools site.
If its still not working what does the debugging console tell you (Firefox/Chrome)?
Add tabletools swf file to your datatable options, and add the datatables js and css files to your code
$('#status_table').DataTable({
"tableTools": {
"sSwfPath": "packages/datatables-tabletools/swf/copy_csv_xls_pdf.swf"
}
});
How do I make a replacement result html tag when using Gii without having to change the yii core direct itself to change the outcome ???
Gii By default : framework\gii\generators\crud\templates\default
and result :
<div class="row">
<?php echo $form->labelEx($model,'title'); ?>
<?php echo $form->textField($model,'title'); ?>
<?php echo $form->error($model,'title'); ?>
</div>
But if I want to get HTML Tag like :
<table>
<tr>
<td><?php echo $form->labelEx($model,'title'); ?></td>
<td>:</td>
<td><?php echo $form->textField($model,'title'); ?></td>
<td><?php echo $form->error($model,'title'); ?></td>
</tr>
</table>
Or in any other form appropriate style css and html that I have.
What should I do to get the results of Gii code generated like that?
The The Definitive Guide to Yii has an manual on extending Gii. You can find it here:
http://www.yiiframework.com/doc/guide/1.1/en/topics.gii#extending-gii
I've built a REST webservice and I want to remove the slashes from my json result. I have some data stored in my DB, which one of the fields contains a websitelinks.I can access them through my normal-view which is html and through my json-view. The normal returns de links normal but the json ads slashes to it like:
http:\/\/mywebsite\/company\/upload\/siteman\/thumbnails\/carr\/
How can i remove this? Here is my cakephp code:
// De html view
<h2>View all posts</h2>
<table>
<tr>
<th>Title</th>
<th>Body</th>
</tr>
<?php foreach($images as $image):?>
<tr>
<td><?php echo $image['Image']['id'];?></td>
<td><?php echo $image['Image']['plaatjes'];?></td>
</tr>
<?php endforeach; ?>
</table>
// The json view
<?php
echo json_encode($images);
?>
Use str_replace, like this:
<?php
echo str_replace('\/','/',json_encode($images));
?>
You can also try JSON_UNESCAPED_SLASHES, like this:
<?php
echo json_encode($images,JSON_UNESCAPED_SLASHES);
?>
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
I want to use a custom template system in my php application,
What I want is I want to keep away my php codes from design, I would like to use a tpl file for designs and a php file for php codes
I dont want to use any ready maid scripts. Can any one point out some links link or useful info how to build a php templating system to achieve this
Thank you
The way I do it is to create a template file(.tpl if you wish) and insert markers which will be replaced with str_replace in PHP. The code will look something like this:
For template.tpl file
<body>
<b>Something: </b> <!-- marker -->
</body>
For the PHP
$template = file_get_contents('template.tpl');
$some_data = 'Some Text'; //could be anything as long as the data is in a variable
$template = str_replace('<!-- marker -->', $some_data, $template);
echo $template;
That's it in a nutshell but it can get a lot more complex. The marker can be anything as long as it's unique.
I want to keep away my php codes from design, I would like to use a tpl file for designs
...and mix your tpl codes with "design"!
what's the difference then? :)
PHP itself is efficient templating system.
And nowadays most developers agreed that dividing your PHP code to business logic part and display logic part is most preferable way.
It can be very limited subset of PHP of course. You will need an output operator (<?=$var?>) one, a condition <? if(): ?>...<? endif ?>, a loop <? foreach(): ?>...<? endforeach ?> and include.
An example of such a template:
<table>
<? foreach ($data as $row): ?>
<tr>
<td><b><?=$row['name'] ?></td>
<td><?=$row['date'] ?></td>
</tr>
<tr>
<td colspan=2><?=$row['body'] ?></td>
</tr>
<? if ($row['answer']): ?>
<tr>
<td colspan=2 valign="top">
<table>
<tr>
<td valign="top"><b>Answer: </b></td>
<td><?=$row['answer'] ?></td>
</tr>
</table>
</td>
</tr>
<? endif ?>
<? if($admin): ?>
<tr>
<td colspan=2>
<? if($row['del']): ?>
show
<? else: ?>
hide
<? endif ?>
edit
</td>
</tr>
<? endif ?>
<? endforeach ?>
</table>