how to Customize pagination phalcon? - pagination

I want to Customize pagination phalcon,
and already read this tutorial
tutorial
but I very confused, how call helper in controller and view ??
and this Customize pagination I want
this image
thanks

In my services.php or Module.php (if multi-module) I have:
...
$loader = new Loader();
$loader->registerNamespaces(
[
'Common\\Library' => SITE_ROOT . 'apps/common/library/',
]
);
$loader->register();
...
My Helpers.php file lives in SITE_ROOT . "/apps/common/library" and has a namespace of:
...
namespace Common\Library;
class Helpers {
...
Now in the controller I can use:
\Common\Library\Helpers::myStaticHelper(<my_vars>);

Related

Find a div in a block render in Symfony

I am doing a site with symfony 4. I start on this framework and I have a problem of design on my site.
I've been looking for where it might come from, but I can not find the code I'd like to remove.
The part of the code I would like to remove is the following because the result is pretty ugly:
I can not find this in my code:
in my controller :
/**
* #return Response
*/
public function newLetterAction(Request $request): Response
{
$form = $this->createForm(CustomerNewsletterType::class, new Customer());
$form->handleRequest($request);
$facebook = $this->manager->getRepository(ExternalUrl::class)->findOneByCode('facebook');
$instagram = $this->manager->getRepository(ExternalUrl::class)->findOneByCode('instagram');
return $this->templatingEngine->renderResponse('#SyliusShop/Homepage/_newsletter.html.twig', [
'facebook' => $facebook,
'instagram' => $instagram,
'form' => $form->createView(),
'rova_refonte' => (in_array($this->container->get('request_stack')->getMasterRequest()->attributes->get('_route'),["sylius_shop_homepage"]) ? true : false)
]);
}
in my formType :
class CustomerNewsletterType extends AbstractResourceType
{
/**
* #param FormBuilderInterface $builder
* #param array $options
*/
public function buildForm(FormBuilderInterface $builder, array $options)
{
$builder
->add('email', EmailType::class, [
'label' => 'app.ui.newsletter',
'attr' => [
'placeholder' => 'app.ui.email'
]
])
;
}
/**
* {#inheritdoc}
*/
public function getBlockPrefix(): string
{
return 'app_customer_newsletter';
}
}
in my twig:
{{ render(controller('app.controller.shop_homepage:newLetterAction')) }}
if anyone could tell me how to find the code, it would help me a lot.
Thank you
Everything is done under the hood when you call $form->createView().
To sum up, every type of field into the form has a base rendering using twig blocks (so does the form itself), which can be overriden. This is what is called the form theme, there's a base one which is usually this one in the twig-bridge.
You can create new themes, extend the existing one, or event create just what you need for a specific form (hint : the getBlockPrefix function in your form type is used for this).
You can find all the documentation about the form rendering here :
https://symfony.com/doc/current/form/form_customization.html
Most functions described in this documentation are in fact calling twig blocks of form themes, and you can find the documentation about this here :
https://symfony.com/doc/current/form/form_themes.html
Keep in mind: Removing such a class / div might break existing CSS, error rendering or everything done in javascript targeting this class.
Most likely you use a bootstrap 3/4 form theme and there works standard form_row template layout.
To customize current form/another form elements, use "How to Work with Form Themes" tutorial.

Dompdf in services not found; Controller error "Message: Class 'Dompdf' not found"

I am working with symphony and slim, so I use services that can be called in my controllers, then to my twig views. I installed Dompdf with composer and added it to my list of services I my bootstrap folder. I have tried several ways to call dompdf, but still get
Message: Class 'Dompdf' not found
This is the code in my controller:
class SlipController extends \App\Controllers\Base\PageController{
function getHandler($request, $response, $args)
{
// Instantiate Dompdf with our options
$dompdf = new Dompdf();
$dompdf->setPaper('A4', 'portrait');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser (force download)
$dompdf->stream("mypdf.pdf", [
"Attachment" => true
]);
return $this->view->render($response,'pages/slips.twig');
}
In the services.php
<?php
$container['dompdf'] = function($container) {
return new \Dompdf\Dompdf;
};
Did you add a use statement to your code?
use Dompdf\Dompdf;
class SlipController extends \App\Controllers\Base\PageController{
function getHandler($request, $response, $args)
{
...

Load Controller With Parameter Opencart

I have created one controller inside catalog/controller/module/same_collection.php
Inside that :
class ControllerModuleSameCollection extends Controller {
//User Product History
public function index($product_id) {
echo $product_id;
}
}
I have try to call it inside another controller like this
$data['same_color'] = $this->load->controller('module/same_color' ,['product_id' => 2] );
and I try to by access it using url like this
mydomain.com/index.php?route=module/same_collection&product_id=2
but it's not working.
Please help!!!
It seems like you have not created your module properly. Make sure your module's setting is saved in module table . If your module's code is not there in the table then you won't get any parameter in your index() method.

Kohana - one function on every controller

I have a project in Kohana 3.3.
I have a lot of controllers, models etc.
Now, I want add one functionality - close the whole site for all users.
Where I can add function, which for example, will redirect users to http://mypage.com/website_is_close ?
Example:
function check(){
$isClose = DB::query(.....)
if($isClose) header("Location: http://mypage.com/website_is_close");
return false;
}
Thanks :)
In Controller_Base all other controllers extend from. E.g.
File application/classes/Controller/Base.php
class Controller_Base extends Controller_Template {
public function before()
{
$isClose = DB::query(.....)
if($isClose)
{
HTTP::redirect("http://mypage.com/website_is_close");
exit ;
}
parent::before();
}
}
All other classes should extend from that class e.g
class Controller_Home extends Controller_Base {}
I personally use this also for every subdirectory e.g.
// As all controllers in the user folder probably need to be supplied with a user anyway
class Controller_User_Base extends Controller_Base {}
class Controller_User_Profile extends Controller_User_Base {}
I think a better approach would be to add a "catch all" route to the beginning of your routes list.
It would catch all URLs and would point to a controller that you would create. This is far cleaner than hacking away at a base controller.
How does this look?
Route::set('closed', '(<url>)', array('url' => '.*'))
->defaults(array(
'controller' => 'Closed',
'action' => 'index',
));

Why can't Kohana find my controller?

I have the following controller:
<?php defined('SYSPATH') or die('No direct script access.');
class Controller_Static extends Controller_DefaultTemplate {
public function action_index()
{
View::set_global('message', '<span class="highlight">This is a global message.</span>');
$data = array (
'siteTitle' => 'Kohana Test Site',
'siteSubtitle' => 'A site to learn Kohana',
'menu' => View::factory('blocks/menu'),
);
$view = View::factory('templates/layout', $data);
$this->request->response = $view->render();
}
}
but kohana gives me the error:
ErrorException [ Fatal Error ]: Class
'Controller_DefaultTemplate' not found
although Eclipse can find the file (via F3) and I thought Kohana was able to find all classes via autoloading?
How can I get Kohana to find the Controller_DefaultTemplate class so I can extend Controller_Static?
You must include file with definition of Controller_DefaultTemplate
The problem was that my file name defaultTemplate.php was camel case, changing it to all-lowercase defaultemplate.php enabled Kohana to find the class inside it.

Resources