Magento2管理员菜单 - 添加外部URL

时间:2018-06-07 16:06:54

标签: magento2

如何向管理员菜单添加外部链接?我已经创建了控制器和动作来重定向,但它无法正常工作。

截图:

enter image description here

2 个答案:

答案 0 :(得分:1)

您可以将以下脚本添加到js文件中:

$('li[data-ui-id="<DATA_UI_ID_OF_THE_MENU>"]').on('click', function (event) {
    event.preventDefault();
    var url = 'https://www.google.com';
    window.open(url, '_blank');
});

答案 1 :(得分:0)

您可以尝试:

  1. 将链接添加到菜单中的控制器(文件/etc/adminhtml/menu.xml)

  2. 创建您的自定义管理控制器(VENDOR / MODULE / Controller / Adminhtml / ...中的类),类似于:

    constructor(){
        super()
    
        this.myRegister = React.createRef()
    }
    
    
    state = {
        ...initiaState
    }
    
    
    changeHandler = (event) => {
    
        this.setState({
            [event.target.name]: event.target.value
        })
    
    }
    
    submitHandler = (event) =>{
        event.preventDefault()
        console.log(this.state)
        this.myRegister.current.reset()
        this.setState({
            ...initiaState
        });
        axios.post(REGISTER_URL,this.state)
        .then(res =>{
            console.log(res)
    
        })
        .catch(error =>{
            console.log("ERROR::: "+error)
        })
    }
    
    render(){
    
        return(
            <div className="Register-box">
    
            <form ref = {this.myRegister} className="Form" onSubmit={this.submitHandler }>
                <div className ="form-group ">
                  <label htmlFor="username" > Name: </label>
                   <input
                   className = "from-control ml-4"
                   type="text" 
                   placeholder = '  Enter Your Name '
                   name = "username"
                   id = "username"
                   value = {this.state.name} 
                   onChange = {this.changeHandler}
                   />
                </div>
    
                <div className ="form-group">
                  <label htmlFor="email" > Email: </label>
                   <input 
                   className = "from-control ml-4" 
                   type="text" 
                   placeholder = '  Enter Your Email '
                   name = "email"
                   id = "email"
                   value = {this.state.email} 
                   onChange = {this.changeHandler}
                   />
                </div>
    
                <div className ="form-group">
                  <label htmlFor="password" className="mr-4"> Password: </label>
                   <input
                   className = "from-control ml-2" 
                   type="password" 
                   placeholder = '  Enter Your Password '
                   name = "password"
                   id = "password"
                   value = {this.state.password} 
                   onChange = {this.changeHandler}
                   />
                </div>
    
    
    
                <button className = "btn btn-primary" type="submit" value="Submit"> Submit </button>
            </form>
    
    
    
            </div>
    
        );
    
    }
    

注意:不要忘记控制器的返回