{"id":17458133,"url":"https://github.com/pocesar/phery-kohana","last_synced_at":"2025-03-21T03:33:25.140Z","repository":{"id":4539985,"uuid":"5680423","full_name":"pocesar/phery-kohana","owner":"pocesar","description":"Kohana 3.3 module with tight integration for Phery.js library https://github.com/pocesar/phery","archived":false,"fork":false,"pushed_at":"2014-11-14T08:30:22.000Z","size":891,"stargazers_count":10,"open_issues_count":0,"forks_count":3,"subscribers_count":4,"default_branch":"master","last_synced_at":"2024-10-18T06:28:24.504Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://github.com/pocesar/phery-kohana","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pocesar.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2012-09-05T00:18:30.000Z","updated_at":"2014-11-14T14:12:51.000Z","dependencies_parsed_at":"2022-08-20T07:31:20.873Z","dependency_job_id":null,"html_url":"https://github.com/pocesar/phery-kohana","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fphery-kohana","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fphery-kohana/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fphery-kohana/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pocesar%2Fphery-kohana/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pocesar","download_url":"https://codeload.github.com/pocesar/phery-kohana/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221811374,"owners_count":16884305,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-10-18T03:55:11.565Z","updated_at":"2024-10-28T09:17:08.967Z","avatar_url":"https://github.com/pocesar.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Phery Kohana\n\nKohana module with tight integration for Phery.js library\n\nWorking with AJAX (including file uploads) never been simpler. Just add the `phery.js` (like `\u003c?php echo HTML::script('phery.js'); ?\u003e`)\nfile on your page (or if you are using an assets manager, add `PHERY_JS` constant to the bunch), and instead of using `Controller`, use\n`Phery_Controller` and instead of `Controller_Template` use `Phery_Template`.\n\nAlso, you should notice that the `$ajax` variable is available in ALL views (but you shouldn't do logic in your views though).\nThis is mainly useful because you need to do a `\u003c?php echo $ajax-\u003ecsrf; ?\u003e` in your head, so you can install CSRF that comes enabled\nby default, otherwise your AJAX calls will fail (CSRF stands for `Cross Site Request Forgery` to avoid remote attacks to your AJAX\nforms and/or links)\n\n##\n\nFor a full documentation of the phery.js library, check [https://github.com/pocesar/phery](https://github.com/pocesar/phery)\n\n## Just follow these conventions:\n\nWhen you want to make a PHP function available for just one action, you namespace it:\n\n```php\nclass Controller_Index extends Phery_Template {\n\n    /* This will be available for action_index only */\n    public function ajax_index_edit()\n    {\n        return PheryResponse::factory()-\u003ealert('works for index!');\n    }\n\n    public function action_index()\n    {\n        $form = array(Phery::form_for('', 'edit'));\n        $form[] = Form::input('id', 1, array('type' =\u003e 'hidden'));\n        $form[] = Form::submit('submit', 'Send');\n        $form[] = Form::close();\n        $this-\u003etemplate-\u003econtent = join('', $form);\n    }\n\n    public function action_view()\n    {\n        // calling phery.remote('edit') from the page won't call the phery_index_edit function\n    }\n}\n```\n\nWhen you want to reuse a callback for all actions, just don't namespace it:\n\n```php\nclass Controller_Index extends Phery_Template {\n\n    /* This will be available for action_index and action_view */\n    public function ajax_edit()\n    {\n        $r = new PheryResponse;\n        /* If you must, check which action the current call should deal */\n\n        switch ($this-\u003erequest-\u003eaction()):\n            case 'index':\n                // do according to index\n                $r-\u003ealert('its for index!');\n                break;\n            case 'view':\n                // do according to view\n                $r-\u003ealert('its for view!');\n                break;\n        endswitch;\n\n        return $r;\n    }\n\n    public function action_index()\n    {\n        $form = array(Phery::form_for('', 'edit'));\n        $form[] = Form::input('id', 1, array('type' =\u003e 'hidden'));\n        $form[] = Form::submit('submit', 'Send');\n        $form[] = Form::close();\n        $this-\u003etemplate-\u003econtent = join('', $form);\n    }\n\n    public function action_view()\n    {\n        $this-\u003etemplate-\u003econtent = Phery::link_to('Click me', 'edit', array('args' =\u003e array('id' =\u003e 1)));\n    }\n}\n```\n\nYou may change the AJAX options per controller, by passing configuration to the `ajax` function inside your controller:\n\n```php\nclass Controller_Index extends Phery_Controller {\n\n    public function ajax()\n    {\n        return array(\n            'error_reporting' =\u003e E_ALL\n        );\n    }\n\n    public function action_index()\n    {\n    }\n}\n```\n\nYour AJAX function will be processed AFTER your `after()` function, so you can place all the transformations, cleanups,\nin there.\n\nAlso, inside the `Phery_Controller` or `Phery_Template`, there is the same `$ajax` variable, so you can mess with `Phery` youself:\n\n```php\nclass Controller_Index extends Phery_Controller {\n\n    function action_index()\n    {\n        $this-\u003eajax-\u003eset(array(\n            'edit' =\u003e 'Helper::staticAjaxMethod',\n            'load' =\u003e array(new Model_User, 'load')\n        ));\n    }\n}\n```\n\nThis make it highly flexible, so you don't need to be tied to convention.\n\nIf any exception happens when using AJAX, it will go 'silently' to your `application/logs` and it will fail with an\nempty JSON response `{}`\n\n## Coming soon\n\n* Render view partial views out of the box (without having to do `$this-\u003eajax-\u003erender_view`\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fphery-kohana","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpocesar%2Fphery-kohana","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpocesar%2Fphery-kohana/lists"}