{"id":18772468,"url":"https://github.com/eftec/example-search","last_synced_at":"2025-12-12T20:30:15.704Z","repository":{"id":71041656,"uuid":"256507565","full_name":"EFTEC/example-search","owner":"EFTEC","description":"It is a library","archived":false,"fork":false,"pushed_at":"2020-04-17T14:44:46.000Z","size":40,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-12-29T08:13:36.881Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://www.eftec.cl","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/EFTEC.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2020-04-17T13:16:02.000Z","updated_at":"2024-09-23T21:04:00.000Z","dependencies_parsed_at":"2023-06-30T01:16:37.689Z","dependency_job_id":null,"html_url":"https://github.com/EFTEC/example-search","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-search","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-search/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-search/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/EFTEC%2Fexample-search/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/EFTEC","download_url":"https://codeload.github.com/EFTEC/example-search/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239680808,"owners_count":19679505,"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-11-07T19:29:11.242Z","updated_at":"2025-12-12T20:30:14.718Z","avatar_url":"https://github.com/EFTEC.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# example-search\nA basic example to create a search feature in php\n\nbootstrap version\n\n![](img/search_bootstrap.jpg)\n\nvanilla html\n\n![](img/search.jpg)\n\n## Configure Composer.\n\nFor this step, you will need composer. Install composer and runs the next line (in the root folder of the project)\n\nYou chould change the values indicates with **  \n\n\u003e composer init\n\n\n```\n Welcome to the Composer config generator\nPackage name (\u003cvendor\u003e/\u003cname\u003e) : **jorge/example-search**\nDescription []:\nAuthor \u003cyou name\u003e, n to skip]:\nMinimum Stability []:\nPackage Type (e.g. library, project, metapackage, composer-plugin) []: **project**\nLicense []: **MIT**\nDefine your dependencies.\nWould you like to define your dependencies (require) interactively yes?\nSearch for a package: **eftec/bladeone**\nEnter the version constraint to require (or leave blank to use the latest version):\nUsing version ^3.37 for eftec/bladeone\nEnter package # to add, or the complete package name if it is not listed: **eftec/bladeone**\nEnter the version constraint to require (or leave blank to use the latest version):\nUsing version ^1.33 for eftec/pdoone\nSearch for a package:\nWould you like to define your dev dependencies (require-dev) interactively yes? **no**\n\n{\n    \"name\": \"jorge/example-search\",\n    \"type\": \"project\",\n    \"require\": {\n        \"eftec/bladeone\": \"^3.37\",\n        \"eftec/pdoone\": \"^1.33\"\n    },\n    \"license\": \"MIT\",\n    \"authors\": [\n        {\n            \"name\": \"you\",\n            \"email\": \"you email\"\n        }\n    ]\n}\n\nDo you confirm generation yes? **yes**\nWould you like the vendor directory added to your .gitignore yes? **yes**\nWould you like to install dependencies now yes? **yes**\nLoading composer repositories with package information\nUpdating dependencies (including require-dev)\n```\n\nIt will create a file called composer.json. It also will create a folder called vendor (with the libraries)\n\n## Create folder views and compiles (for the templates)\n\n📁 root project   \n📁 composer.json (created in the previous step)   \n---- 📁 vendor (created in the previous step)  \n____ 📁 compiles  \n____ 📁 views   \n\n\n## Connect to the database\n\nincluding vendor/autoload.php will deal with all the (ahem) includes.   :-3\n\n```php\ninclude \"vendor/autoload.php\";\n```\n\nWe will use PdoOne to connect to the database.\nType of database :mysql, server =127.0.0.1, user=root, password =abc.123, database=sakila \n(you must change it according your config) \n\n\n```php\nuse eftec\\PdoOne;\n$pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');\n$pdoOne-\u003econnect();\n```\n\n## Creating exampling data and the table (optional)\n\nIf the table does not exist, then it will create.  \nIt also will add example data.  \n\n```php\nif (!$pdoOne-\u003etableExist('test_products')) {\n    // No, then let's create a new table\n    $pdoOne-\u003ecreateTable('test_products'\n    ,['idProduct'=\u003e'int not null','name'=\u003e'varchar(50)']\n    ,['idProduct'=\u003e'PRIMARY KEY']);\n    \n    // and let's add some example data\n    $pdoOne-\u003einsertObject('test_products', ['idProduct'=\u003e1,'name'=\u003e'Cocacola']);\n    $pdoOne-\u003einsertObject('test_products', ['idProduct'=\u003e2,'name'=\u003e'Fanta']);\n    // another way to insert values\n    $pdoOne-\u003eset(['idProduct','i',3,'name','s','Sprite'])\n           -\u003einsert('test_products');\n}\n```\n\n## Creating the view\n\nWe will use BladeOne for view.\n\nIt will use the folders views and compiles  (created in a previous step).\n\n### Creating the instance\n\n```php\nuse eftec\\bladeone\\BladeOne;\n$blade=new BladeOne();\n```\n\n### using it\n\nThe view is called \"list\", so we must create the next file (in the folder views/)\n\nviews/list.blade.php  \n\n```\n\u003cbody\u003e\n....\n\u003c/body\u003e\n```\n\n\nWe will pass to the view the next data searchText and Result.   \n\n```php\necho $blade-\u003erun('list'\n    ,[\n        'searchText'=\u003e$searchText\n         ,'result'=\u003e$result\n     ]);\n```\n\n## Joining all together\n\nSee search.php or search_bootstrap.php file\n\n```php\n\u003c?php /** @noinspection PhpUnhandledExceptionInspection */\n\nuse eftec\\bladeone\\BladeOne;\nuse eftec\\PdoOne;\n\ninclude \"vendor/autoload.php\";\n\n$pdoOne=new PdoOne('mysql','127.0.0.1','root','abc.123','sakila');\n$pdoOne-\u003econnect();\n\n// Does the table exist?\n\nif (!$pdoOne-\u003etableExist('test_products')) {\n    // No, then let's create a new table\n    $pdoOne-\u003ecreateTable('test_products'\n    ,['idProduct'=\u003e'int not null','name'=\u003e'varchar(50)']\n    ,['idProduct'=\u003e'PRIMARY KEY']);\n    \n    // and let's add some example data\n    $pdoOne-\u003einsertObject('test_products', ['idProduct'=\u003e1,'name'=\u003e'Cocacola']);\n    $pdoOne-\u003einsertObject('test_products', ['idProduct'=\u003e2,'name'=\u003e'Fanta']);\n    // another way to insert values\n    $pdoOne-\u003eset(['idProduct','i',3,'name','s','Sprite'])\n           -\u003einsert('test_products');\n}\n\n$button=@$_POST['button'];\n\nif($button) {\n    // we press the button\n    $searchText=@$_POST['searchText'];\n    $result=$pdoOne-\u003eselect('*')-\u003efrom('test_products')-\u003ewhere('name like ?',[\"%$searchText%\"])-\u003etoList();\n    if($result===false) {\n        // result is false if the operation failed.\n        $result=[];\n    }\n} else {\n    $searchText='';\n    $result=$pdoOne-\u003eselect('*')-\u003efrom('test_products')-\u003etoList();\n}\n\n$blade=new BladeOne();\n\necho $blade-\u003erun('list'\n    ,[\n        'searchText'=\u003e$searchText\n         ,'result'=\u003e$result\n        ,'count'=\u003ecount($result)\n     ]);\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample-search","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feftec%2Fexample-search","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feftec%2Fexample-search/lists"}