I have a
Controller/PostsController.php
Model/Post.php
View/Posts/Index.ctp
if anyone has followed the cakephp blog tutorial i have completed that.
Anyone who hasnt, its basically a site that lets you add a title and a comment. Much like a forum.
Now i have this set up , but i want to include a new page called home. And on this page i wont to display the forum i created but in a smaller container.
I am unsure how to add the view of Posts to a new controller/model/view.
This is PostsController.php:
class PostsController extends AppController {
public function index() {
$this->set('posts', $this->Post->find('all'));
}
}
This is View/Posts/index.ctp
<table>
<tr>
<th>Id</th>
<th>Title</th>
<th>Actions</th>
<th>Created</th>
</tr>
<!-- Here's 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']
);
?>
</td>
<td>
<?php echo $post['Post']['created']; ?>
</td>
</tr>
<?php endforeach; ?>
</table>
so with this, how do i get the same posts to include on a new controller and view, lets say:
HomesController.php
View/Homes/index.ctp
EDIT//EDIT//EDIT
right i have managed to do half of this now by adding
$this->render('/Abouts/index');
to my PostsController
but now i get an error saying
"Undefined variable: posts [APP\View\Abouts\index.ctp, line 12]"
im not sure how to define these in my abouts view
In the 'abouts' action, you'd do the same thing you were doing in the index:
$this->set('posts', $this->Post->find('all'));
Site note: Seems like it would be worth your time to go through the blog tutorial again for a refresher. I believe this kind of thing is covered pretty thoroughly.
From cakephp books
Many applications have small blocks of presentation code that need to be repeated from page to page, sometimes in different places in the layout. CakePHP can help you repeat parts of your website that need to be reused. These reusable parts are called Elements. Ads, help boxes, navigational controls, extra menus, login forms, and callouts are often implemented in CakePHP as elements. An element is basically a mini-view that can be included in other views, in layouts, and even within other elements. Elements can be used to make a view more readable, placing the rendering of repeating elements in its own file. They can also help you re-use content fragments in your application.
So, for your purposes use elements, more information here
Related
I am getting stuck in horizontal table(apex) which I need to share inside the email template.Table structure would be like below:
Html Table
Earlier, I am giving space between them by using ensp; or nbsp; but whenever the data is filling out in these fields, their alignment is not coming correctly.So that I need table instead of using these ( or )
I'm going to make a couple of assumptions here. If these assumptions are wrong, you're kind of SOL.
that you're using a Visualforce Email template
that your comfortable writing both the visualforce and the apex controller
You're aware of how to get a handle on the necessary objects and fields you want to display
If those three things are true, this is actually just an example of how weird visualforce can be.
Visualforce allows you to mix in regular HTML, so the HTML for a table like your image would look something like this:
<table>
<tbody>
<tr>
<td colspan="2">OpportunityNameVar</td>
</tr>
<tr>
<td>AccountNameVar</td>
<td>Opp Type</td>
</tr>
<tr>
<td>Phone</td>
<td>CloseDate</td>
</tr>
</tbody>
</table>
I'm developing a web app using sencha touch and I'm using sencha architect, I want to add a condition to my list itemtpl to view difference in customer's balance:
balance>=0 --> green
balance<0 --> red
This is my basic itemtpl:
<table width="100%"><tr>
<td>{c_name}</td>
<td width="95px">
<div style="width:95px;height:100%;background:#088cfc;text-align:center;color:#fff;">{balance}</div>
</td>
</tr>
</table>
How can I add xtemplate using sencha architect IDE and link it to my list?
thank you,
Old question but I wanted an answer to the same problem when dealing with how to "Use an XTemplate in Architect" which is what the title states and the Answer given does not actually show a beginning user an answer on how to do this in Architect in my opinion.
So the steps are:
So add your component to the Architect canvas or within what ever component you are using.
Next go to the Configs list and find the entry for 'Process Config' and click the plus sign
next you will get a function that allows you to update and process any of the current Config settings or add your own. My function is called 'processMyView' (I am using a dataview for my example, ergo the name)
add some javascript that creates the 'tpl'
ensure you return the 'config' parameter at the end of the function
In my example I had a list of Documents with title and owner and so the end result will look like this.
In the end anytime you are being frustrated by Architect, this may be one of the approaches you can take to get around the IDE's rigidity for a Config setting.
I'm actually using XTemplate in architect just use > and < instead of '<' and '>' in your condition:
if balance>0 ==> use: if balance > 0 see below:
<table width="100%"><tr>
<td>{c_name}</td>
<td width="95px">
<tpl if="balance > 0">
<div style="border-radius:5px;;width:95px;height:100%;background:#088cfc;text-align:center;color:#fff;font-size:12px;height:23px;padding-top:4px;">{balance} ₪</div>
</tpl>
<tpl if="balance < 0">
<div style="border-radius:5px;;width:95px;height:100%;background:#f00;text-align:center;color:#fff;font-size:12px;height:23px;padding-top:4px;">{balance} ₪</div>
</tpl>
</td>
</tr>
</table>
Can we do something like image below on cakephp. If can, how to do it? I am struggle with it. I try to find any answers but can not found something like this. Any answers for this problem will be great appreciated.
This can also be done with Bootstrap as well. The functionality is generally the same as #Anubhav 's answer from a bit earlier, however this is a little cleaner and a more up to date solution. The Bootstrap Framework is maintained/updated a lot more frequently.
See here for full solution:
Bootstrap dropdown checkbox select
No you cant do this using only CakePHP... but the above thing can be done using jQuery.
Please follow the link and your task will be done easily
http://dropdown-check-list.googlecode.com/svn/trunk/doc/dropdownchecklist.html
Cheers
multiple dropdown options with checkbox in cakephp error
<div class="col-md-2 place-grid">
<h5>Property Type</h5>
<?php $allCategories=$this->Common->getCategories(); ?>
<?php echo $this->Form->input('ptype',array('options' =>$allCategories,'style'=>'width:150px;','error'=>false,'id'=>'ptype','onchange'=>'getIdType()','div'=>false,'label'=>false,'empty'=>'Select Type','class'=>"sel")); ?>
<?php if($this->Form->error('ptype')){?>
<?php echo $this->Form->error('ptype',array('style'=>'txtError'));?>
<?php } ?>
</div>
<div class="col-md-2 place-grid">
<h5>Sub Type</h5>
<?php $allSubCategories=$this->Common->getArticleSubCategories(); ?>
<?php echo $this->Form->input('sptype',array('options'=>'', 'style'=>'width:150px;','error'=>false,'div'=>false,'select'=>true,'label'=>false,'empty'=>'fgfg','class'=>"sel")); ?>
</div>
I have a form which updates multiple records in a table and is working fine. I want too be able to add new records via ajax am loading the following in via ajax but am getting blackholed
<?
$uuid = String::uuid();
?>
<tr>
<?=$this->Form->input('Attachment.'.$uuid.'.id',array());?>
<?$this->Form->unlockField('Attachment.'.$uuid.'.id');?>
<td><?=$this->Form->input('Attachment.'.$uuid.'.title',array('label'=>false,'style'=>'float:left;'));?></td>
<?$this->Form->unlockField('Attachment.'.$uuid.'.title');?>
<td><?=$this->Form->input('Attachment.'.$uuid.'.url',array('label'=>false,'style'=>'float:left;'));?> <button onclick="return false;" class="btn attachment_select_file" style="float:left;"><i class="icon-folder-open"></button></i></td>
<?$this->Form->unlockField('Attachment.'.$uuid.'.url');?>
<td><button class="btn"><i class="icon-trash icon-large"></i></button></td>
</tr>
Does anyone have any idea what might be causing this.
Thanks
"There may be cases where you want to disable all security checks for an action (ex. ajax request). You may “unlock” these actions by listing them in $this->Security->unlockedActions in your beforeFilter." - from The cook book
The first thing I'd be doing is disabling the security component completely and seeing if that fixes it. If it does, then re-enable the security component, and add the relevant action to
$this->Security->unlockedActions
in your beforeFilter.
I am trying to display string array in JSP page.
I have got a test String array in my controller set this to my registration model
String[] test={"ab","cb","sc","ad"};
registration.setTestArray(test);
Now I am trying to display it in jsp Its working fine if I do like this
<tr>
<c:forEach var="arr" items="${registration.testArray}">
<td>${arr} </td>
</c:forEach>
</tr>
But my problem is I want to display only some of the values from this array like 2nd and 4th index of this array.
I tried like
<tr>
<c:forEach var="arr" items="${registration.testArray}">
<td>${arr[2]} </td>
</c:forEach>
</tr>
but its throwing an error. This is just a test in my actual project I have long array of array from which I have to display some selected values.
I am thinking of doing this by first process my required values in controller and then display it in jsp. But I am not sure is this the best method. It would be great help if someone suggest me the better way.
It depends on how you get these "selected values". You can:
${registration.testArray[2]}
you can loop using a specific step of the c:forEach tag
you can loop everything and check <c:if test="${selectedValues.contains(arrItem)}