PHP code example of atans / atans-common

1. Go to this page and download the library: Download atans/atans-common library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

atans / atans-common example snippets


    public function textAction()
    {
        // Text
        return $this->ajax()->html('<strong>html</strong>');
        // Content-Type: text/html
        // Output: <strong>html</strong>
    }

    public function textAction()
    {
        // Text
        return $this->ajax()->text('text');
        // Content-Type: text/plain
        // Output: text
    }

    public fucntion statusTestAction()
    {
        return $this->ajax()->status('ok', 'Ok message');
        // Content-Type: application/json
        // Output : {"status" : "ok", "message" : "Ok message"}

        return $this->ajax()->status('ok', 'Ok message', array('data' => 'Returns data'));
        // Output : {"status" : "ok", "message" : "Ok message", "data" => "Retruns data"}

        return $this->ajax()->status('ok', array('data' => 'Returns data'));
        // Output : {"status" : "ok", "data" => "Retruns data"}
    }

    public fucntion successTestAction()
    {
        return $this->ajax()->success(true, 'Ok message', array('data' => 'Returns data'));
        // Content-Type: application/json
        // output : {"success" : true, "message" : "Ok message", "data" => "Retruns data"}

        return $this->ajax()->success(false, 'False message');
        // Output : {"success" : false, "message" : "False message"}

        return $this->ajax()->success(true, array('data' => 'Returns data'));
        // Output : {"success" : true, "data" => "Retruns data"}
    }

    public function indexAction()
    {
        $id = (int) $this->params()->formRoute('id', 0);

        // Default object manager is doctrine.entitymanager.orm_default
        $entity = $this->objectManager()->find('Application/Entity/EntityName', $id);
        // or
        $entity = $this->objectManager('doctrine.entitymanager.orm_other')->find('Application/Entity/EntityName', $id);
    }

    public function indexAction()
    {
        $message = $this->translate('This is a message');

        // Same as
        $translator = $this->getServiceLocator()->get('Translate');
        $message    = $translator->translate('This is a message');
    }

    echo \AtansCommon\Text\String::cut('This is a longer text', 6);
    // output : This i...

    public function indexAction()
    {
        $this->flashMessenger()
             ->setNamespace('application-index')
             ->addSuccessMessage('Message text');

        ...

        return array();
    }

    //application/index/index.phtml
     echo $this->render('alert/bootstrap', array('namespace' => 'application-index')) 

    // application/layout/layout.phtml
    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
        <div class="container">
            <div class="navbar-header">
            ...
            <div class="collapse navbar-collapse">
                 echo $this->navigation('navigation')->menu()->setPartial(array('navigation/bootstrap', 'default'))->render() 

    // user/user/index.phtml
    
        echo $this->paginationControl(
            $this->paginator,
            'Sliding',
            'pagination/query',
            array(
                'route' => 'user',
                'options' => array(
                    'query' => array(
                        'keyword' => $keyword,
                    ),
                ),
            )
        );
    
html
<ul class="pagination">
  <li class="disabled"><a href="#">&laquo;</a></li>
  <li><a href="/user?page=1&keyword=test">1</a></li>
  <li><a href="/user?page=2&keyword=test">2</a></li>
  <li><a href="/user?page=3&keyword=test">3</a></li>
  <li><a href="/user?page=2&keyword=test">&raquo;</a></li>
</ul>