I am working in cakephp application.
Here all the calls happening with Ajax. So user wants to keep one button or link, when user click on the link it will show one with contains help info of that page. I'm able load div with right content. But dynamically I'm not able to display one link (Show Help) on the page dynamically.
The reason for the "Show Help" link dynamic is based on which page loads I have to pass value to JavaScript function.
Plz help me how to add this link in $content_for_layout so that it will display dynamically in all the pages.
Step1: This is the code to create helper. Put the following code in app/views/helpers/LinkHelper.php
class LinkHelper extends AppHelper {
var $helpers = array('Html');
function showHelp() {
$url = '';//create your url dynamically here
$title = 'Show Help';
return $this->Html->link($title, $url, array('class' => 'help'));
}
}
Step2: Load the Link Helper in layout
$HelpLink = $this->Helpers->load('Link');
Step3: Call showHelp method of LinkHelper where Show Help link to be shown.
echo $HelpLink->showHelp();
Related
Currently I am using SS4 Blog module.
We have used a paginated style of blog.
And now we need a load more ajax for more content.
Any idea on how to do this in SS4?
I am searching for an example of this but the community was not able to give me an answer.
Though your question is not clear, I will try to answer it in the way I think will make sense.
Pagination: This view is like a book were you actually have to flip through each "Page". If you are on Page 2, you won't see what's on Page 1.
LoadMore: You start on Page 1 then you append results of Page 2 to the View where Page 1 is. This way you can view Page 1 and Page 2 on the same Page creating a stack of pages.
For LoadMore which you asked.
You need a js variable var currentPage = 1; to hold the current page to be loaded from the server. Each time you request data you will need to provide the current page you are on. Logically something like this
You render your page with Page1 loaded; currentPage = 1;
OnClickingLoadMore button; currentPage++;
Send the request via ajax. var url = 'server.com/posts/pull?page='+currentPage;
Append returned data on the current view.
PostsController.php
add the method name to the allowed-action
private static $allowed_actions = [
'pull',
];
Create a method called "pull" with the code below in it.
$oListings = BlogPost::get();
$oList = new PaginatedList( $oListings, $this->request );
$oList->setPageLength( $limit );
$oList->setCurrentPage( $page );
Lastly your routes.yml (simplified)
SilverStripe\Control\Director:
rules:
'posts//$Action/$ID/$OtherID': 'PostsController'
Lastly using jQuery you can APPEND [http://api.jquery.com/append/] to add more content to your page.
Hope this helps
I am using javascript for showing a link in php Codeigniter. But I want
toredirect to a new php page with new tab when click the link . my
controller is loginController and my function is downloadPdf().
how to do this.
my java script is
contentRow += '<div>click here</div>';
and this javascript code will append to div in php code
my need is when i click this link ,i have to pass a parameter to the redirecting page for some process.but with codeignitor
use the HTML a target='_blank' attribute to link.
I am trying to load a view from a controller but i am not able to do so? I am not getting any error but the view doesn't appear. In the search input field of my page i use ajax to get suggestions from the db for the typed in text:
function get_users($hint)
{
if($hint!="")
{
$this->db->select('email,first_name');
$this->db->like('email',$hint,'after');
$query=$this->db->get('users');
$row=$query->result_array();
$name=$row[0]['first_name'];
echo "<a href=/codeigniter/index.php/user_view/view_profile/$name >".$name."</a><br>";
}
else
{
echo "";
}
}
This sends the name of user as a link to the view. When i click the link it calls a controller which then loads the profile of the user (say whose name is contained in $name).
the code of that controller is
function view_profile($name)
{
$data['user']=$name;
$this->load->view('profile',$data);
}
A new page opens but the profile doesn't load. It's just a blank page. Can anybody help?
Why not redirect to user_view/view_profile right from get_users function?
I mean instead of echo "".$name."";
you may try to write redirect('user_view/view_profile/'.$name);
And one more thing in config/config.php enable logs (If you haven't enabled them yet) , log files are so usefull in troubleshooting.
I am trying to call the default joomla user registration form through a custom module with link. I created a popup box and i would like to show the user login and user registration inside that popup box. I just need the call for the forms. Thanks
You can use the getInstance() method of JForm where the first parameter is the name form (arbitrary) and the second parameter is the absolute path to the xml containing the form (in joomla forms are created with xml files).
<?php
/* #var $form JForm */
$form = JForm::getInstance('formName', JPATH_BASE . '/components/com_users/models/forms/registration.xml');
foreach ($form->getFieldset() as $field) {
echo JText::_($field->label);
echo $field->input;
}
?>
Hope this helps :)
Stoyan
The custom module should be published to a component if you want to be able to access it. You can achieve this with com_content and the {loadposition } code.
Once you have your module in a component, you need to figure out a link to it, it could be:
http://example.com/index.php?option=com_content&view=article&id=115
of a sef-url if you define a menu item.
To invoke just the component (thus the module's) output, add
&tmpl=component
to the url, this will tell Joomla to only render the component and not the full template
I am using Agile Toolkit. I have a drop-down field in my CRUD.
How can I make the "New" button display different set of values in this drop-down to when the "Edit" button is clicked?
Here is my code:
class page_things extends Page {
function init(){
parent::init();
$p = $this;
$f = $p->add('Form');
$idCat = ($f->get('idCat')?$f->get('idCat'):$this->api->getConfig('idCat','MASP2U03'));
$dpUE = $f->addField('dropdown', 'Category');
$dpUE->setModel('Category');
$dpUE->js('change',$f->js()->submit());
$dpUE->set($idCat);
$f->addSubmit('OK');
$c = $f->add('CRUD');
$c->setModel('things',array('name', 'field1', 'field2', 'field3'))->setMasterField('idCat',$idCat);
if($f->isSubmitted()){
$c->js(true)->show()->execute()->reload()->execute();
}
}
}
Thank you for help !!
use
$crud=$this->add('CRUD',array('allow_add'=>false));
to disable default Add button, then add your own button:
if($crud->grid)$crud->grid->addButton('Add')->js('click')
->frameURL('Add',$this->api->url('./new'));
After this you'll need to create a new page
class page_things_new extends Page {
and inside this page define the form the way you want it to appear no the "add" click. I don't fully understand your question, but with these instruction you can have a different page appear when adding new entries to your crud.
Here's an alternative to Romans that I've tried. It uses $this->api->memorize to store a GET variable chosen in the drop down list in a session variable. Then in the Form, you can set default the chosen value by using recall in the model.
Something like this
in page/things
// load the javascript function (see later)
$this->js()->_load('your_univ');
/*****************************************************************/
/* Code to populate drop down lists - amend where as required*/
$catList=$this->api->db->dsql()->table('category c')
->field('c.id')
->field('c.name')
->where('c.type',$cat_type)
->order('c.id')
->do_getAssoc();
// Check if one is set on URL or default from config and memorize the value
if ($_GET['cat']){
$cat=$_GET['cat'];
} else {
$cat=$this->api-getConfig('idCat');
}
$this->api->memorize('category',$cat);
$f=$p->add('Form',null,null,array('form_empty'))
->setFormClass('horizontal bottom-padded');
$l1=$f->addField('dropdown','category')->setValueList($catList)->set($cat);
// calls a bit of javascript described later to reload with the parameter
$l1->js('change')->univ()->yourfunc($p->api->getDestinationURL(null), $l1);
.. rest of your page code goes here ..
Then in /lib/Model/Category.php
Add the following recall for the field
$this->addField('idCat')->system(true)->visible(false)
->defaultValue($this->api->recall('category'));
Note the system(true) and visible(False) means it wont show up and wont be changeable on the CRUD but you can play around with the options so it shows in the CRUD grid but not in the form.
Finally, the little bit of javascript to make the reload work (Romans might advise a better way to do this). Make sure yourfunc matches in the page and in the js.
in /templates/js/your_univ.js add the following
$.each({
yourfunc: function(url, name){
document.location.href=url+'&cat='+$(name).val();
},
},$.univ._import);
I've got code similar to this working in my own pages. You can probably make it work as a POST as well as the drop down is a form if you dont want the cat to show on the URL.