How Laravel references third-party (custom) libraries
想做一个网页抓取的功能,底层使用php的laravel框架。
这里使用phpQuery库来实现网页抓取,这里不做介绍。
需要了解的可以百度,或者等我填坑。
不能科学上网的可以直接点击我上传的下载包- -|怎么上传。。。自己百度吧,目前最新的版本是phpQuery-0.9.5.386
-------------------------------------
先申明下我用的版本:
laravel5.1;
phpQuery-0.9.5.386;
-------------------------------
开始以为只要把库整个包扔进laravel工程就能用了,果然是图样图森破。
鉴于laravel框架封装的良好行,这里需要设置laravel的autoload->class map
-------
1、首先在app目录下创建一个新的文件夹,命名libs(可自定义)
2、(可选)考虑到后面可能会引用很多库,so,在libs下再创建一个phpQuery文件夹
3、找到根目录下的composer.json文件
4、找到composer.json中定义的(看我备注)
"autoload": { "classmap": [ "database", "app/libs/phpQuery" //加我 加我 加我 ], "psr-4": { "App\\": "app/" } },
5、运行终端,cd到项目路径,执行
composer dumpautoload
--------------------------
然后就能在项目中愉快的使用phpQuery了,简单的用法如下:
use phpQuery;
phpQuery::newDocumentFile('http://www.baidu.com'); $companies = pq('body'); return $companies;
注:如果要再加其他第三方库,重复2-5的步骤即可。
以上就介绍了Laravel如何引用第三方(自定义)库,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Apple's products and services have always been loved by users around the world. Registering a Hong Kong Apple ID will bring more convenience and privileges to users. Let’s take a look at the steps to register a Hong Kong Apple ID and what you need to pay attention to. How to register a Hong Kong Apple ID When using Apple devices, many applications and functions require using Apple ID to log in. If you want to download applications from Hong Kong or enjoy the preferential content of the Hong Kong AppStore, it is very necessary to register a Hong Kong Apple ID. This article will detail the steps on how to register a Hong Kong Apple ID and what you need to pay attention to. Steps: Select language and region: Find the "Settings" option on your Apple device and enter

Blackmagic Design has finally brought its well-praised Blackmagic Camera app to Android. The professional video camera app is free to download, and it offers complete manual controls. These controls aim to make it easier for you to take pro-level cin

The latest versions of Laravel 9 and CodeIgniter 4 provide updated features and improvements. Laravel9 adopts MVC architecture and provides functions such as database migration, authentication and template engine. CodeIgniter4 uses HMVC architecture to provide routing, ORM and caching. In terms of performance, Laravel9's service provider-based design pattern and CodeIgniter4's lightweight framework give it excellent performance. In practical applications, Laravel9 is suitable for complex projects that require flexibility and powerful functions, while CodeIgniter4 is suitable for rapid development and small applications.

For beginners, CodeIgniter has a gentler learning curve and fewer features, but covers basic needs. Laravel offers a wider feature set but has a slightly steeper learning curve. In terms of performance, both Laravel and CodeIgniter perform well. Laravel has more extensive documentation and active community support, while CodeIgniter is simpler, lightweight, and has strong security features. In the practical case of building a blogging application, Laravel's EloquentORM simplifies data manipulation, while CodeIgniter requires more manual configuration.

When choosing a framework for large projects, Laravel and CodeIgniter each have their own advantages. Laravel is designed for enterprise-level applications, offering modular design, dependency injection, and a powerful feature set. CodeIgniter is a lightweight framework more suitable for small to medium-sized projects, emphasizing speed and ease of use. For large projects with complex requirements and a large number of users, Laravel's power and scalability are more suitable. For simple projects or situations with limited resources, CodeIgniter's lightweight and rapid development capabilities are more ideal.

Laravel - Artisan Commands - Laravel 5.7 comes with new way of treating and testing new commands. It includes a new feature of testing artisan commands and the demonstration is mentioned below ?

Composer manages dependencies by using the composer.lock file, which records all installed dependencies and their exact versions, making it: Ensure consistency and avoid version conflicts. Improve performance without having to search for packages repeatedly. Track changes, recording installed dependency versions after each install command.

For small projects, Laravel is suitable for larger projects that require strong functionality and security. CodeIgniter is suitable for very small projects that require lightweight and ease of use.
